Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pipet[2];
- pid_t pid1;
- pid_t pid2;
- int status;
- if (pipe(pipet) == -1)
- _exit(EXIT_FAILURE);
- pid1 = fork();
- if (pid1 == 0)
- {
- close(pipet[0]);
- dup2(pipet[1], 1);
- execvp(code);
- }
- pid2 = fork();
- if (pid2 == 0)
- {
- close(pipet[1]);
- dup2(pipet[0], 0);
- execvp(code);
- }
- close(pipet[0]);
- close(pipet[1]);
- wait(&status); // waits for one child to finish
- wait(&status); // waits for the other child to finish
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement