Advertisement
d1cor

pipe_duplex1.c

Jun 7th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 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 tubo[2];
  15.     char buf[BUF_SIZE];
  16.     pipe(tubo);
  17.  
  18.     if(!fork()){
  19.         int count = read(tubo[0],buf,BUF_SIZE);
  20.         *(buf+count)='\0';
  21.         printf("Hijo R:%s\n",buf);
  22.  
  23.         write(tubo[1],"hijo listo",10);
  24.  
  25.         close(tubo[0]);
  26.         close(tubo[1]);
  27.         _exit(0);
  28.  
  29.     }
  30.  
  31.     write(tubo[1],"padre enviando",14);
  32.     sleep(1);
  33.     int count = read(tubo[0],buf,BUF_SIZE);
  34.     *(buf+count)='\0';
  35.     printf("Padre R:%s\n",buf);
  36.     close(tubo[0]);
  37.     close(tubo[1]);
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement