Advertisement
d1cor

pipe_duplex2.c

Jun 7th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /*
  2.  * Author: - @d1cor - juncotic.com
  3.  * Date: 07/jun/2017
  4.  */
  5.  
  6. #include<stdio.h>
  7. #include<unistd.h>
  8. #include<wait.h>
  9.  
  10. #define BUF_SIZE 1024
  11.  
  12. int main(int argc, char** argv){
  13.  
  14.     int p_h[2];
  15.     int h_p[2];
  16.     char buf[BUF_SIZE];
  17.     pipe(p_h);
  18.     pipe(h_p);
  19.  
  20.     if(!fork()){
  21.         close(p_h[1]);
  22.         close(h_p[0]);
  23.         int count = read(p_h[0],buf,BUF_SIZE);
  24.         *(buf+count)='\0';
  25.         printf("Hijo R:%s\n",buf);
  26.  
  27.         write(h_p[1],"hijo listo",10);
  28.  
  29.         close(p_h[0]);
  30.         close(h_p[1]);
  31.         _exit(0);
  32.  
  33.     }
  34.     close(p_h[0]);
  35.     close(h_p[1]);
  36.  
  37.     write(p_h[1],"padre enviando",14);
  38.     int count = read(h_p[0],buf,BUF_SIZE);
  39.     *(buf+count)='\0';
  40.     printf("Padre R:%s\n",buf);
  41.     close(h_p[0]);
  42.     close(p_h[1]);
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement