Advertisement
Guest User

double pipe

a guest
Jul 23rd, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <error.h>
  6. #include <sys/types.h>
  7.  
  8. int main(int argc, char **argv){
  9.     int p[2], p1[2], pid, n, m;
  10.     char buf[10], buf1[10];
  11.     pipe(p);
  12.     pipe(p1);
  13.     pid = fork();
  14.     if(pid){
  15.         close(p[0]);
  16.         close(p1[1]);
  17.         write(p[1],"ciao",5);
  18.         do{
  19.             m = read(p1[0],buf1,10);
  20.         }while(m < 1);
  21.         exit(1);
  22.     }
  23.     else{
  24.         close(p[1]);
  25.         close(p1[0]);
  26.         wait(NULL);
  27.         n = read(p[0],buf,10);
  28.         write(STDOUT_FILENO,buf,n);
  29.         write(p1[1],"ok",3);
  30.         exit(1);
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement