Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2023
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1.         int toSub[2], fromSub[2];
  2.         if(!pipe(toSub)) return 1;
  3.         if(!pipe(fromSub)) return 1;
  4.  
  5.         if( fork() )
  6.         {
  7.                 while(1)
  8.                 {
  9.                         if(!read(fromSub[0], &c, 1)) break;
  10.                         send(sockfd, &c, 1, 0);
  11.  
  12.                         printf("in-%c\n", c);
  13.  
  14.                         if(!recv(sockfd, &c, 1, 0)) break;
  15.                         send(toSub[1], &c, 1, 0);
  16.  
  17.                         printf("out-%c\n", c);
  18.                 }
  19.         }
  20.         else
  21.         {
  22.                 dup2(toSub[0], 0);
  23.                 dup2(fromSub[1], 1);
  24.                 execlp("rz", "rz", (char*) NULL);
  25.         }
  26.  
  27.         puts("done");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement