Advertisement
Guest User

xxxxxx

a guest
Oct 21st, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6.  
  7. int main()
  8. {
  9. int pdesk[2];
  10. if(pipe(pdesk) == -1){
  11.        printf("tworzenie procesu");
  12.        exit(0);
  13.         }
  14.  
  15.        switch(fork()){
  16.           case -1: // blad w tworzeniu procesu
  17.                 printf("Tworzenie procesu");
  18.               exit(0);
  19.           case 0: // proces potomny
  20.                 if (write(pdesk[1], "Hallo!", 7) == -1){
  21.                       printf("Zapis do potoku");
  22.                         exit(0);
  23.                 }
  24.               exit(0);
  25.           default: { // proces macierzysty
  26.                 char buf[10];
  27.               if (read(pdesk[0], buf, 10) == -1){
  28.                         printf("Odczyt z potoku");
  29.                         exit(0);
  30.               }
  31.                 printf("Odczytano z potoku: %s\n", buf);
  32.           }
  33.       }
  34.  
  35. return 0;
  36.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement