Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1.     int pipet[2];
  2.     pid_t pid1;
  3.     pid_t pid2;
  4.     int status;
  5.  
  6.     if (pipe(pipet) == -1)
  7.         _exit(EXIT_FAILURE);
  8.  
  9.     pid1 = fork();
  10.     if (pid1 == 0)
  11.     {
  12.         close(pipet[0]);
  13.         dup2(pipet[1], 1);
  14.         execvp(code);
  15.     }
  16.  
  17.     pid2 = fork();
  18.     if (pid2 == 0)
  19.     {
  20.         close(pipet[1]);
  21.         dup2(pipet[0], 0);
  22.         execvp(code);
  23.     }
  24.  
  25.     close(pipet[0]);
  26.     close(pipet[1]);
  27.  
  28.     wait(&status); // waits for one child to finish
  29.     wait(&status); // waits for the other child to finish
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement