Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <sys/wait.h>
- #include <inttypes.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- int main (int argc, char * argv[]) {
- int fd[2];
- pipe(fd);
- int pidSFir, pidSSec;
- if (!(pidSFir = fork())) {
- int pidGSFir, pidGSSec;
- close(fd[0]);
- dup2(fd[1], 1);
- close(fd[1]);
- if (!(pidGSFir = fork())) {
- execlp(argv[1], argv[1], NULL);
- return -1;
- }
- waitpid(pidGSFir, NULL, 0);
- if (!(pidGSSec = fork())) {
- execlp(argv[2], argv[2], NULL);
- return -1;
- }
- close(fd[1]);
- waitpid(pidGSSec, NULL, 0);
- _exit(0);
- }
- close(fd[1]);
- if (!(pidSSec = fork())) {
- int flDes = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC, 0222);
- dup2(flDes, 1);
- close(flDes);
- dup2(fd[0], 0);
- close(fd[0]);
- execlp(argv[3], argv[3], NULL);
- return -1;
- }
- close(fd[0]);
- waitpid(pidSFir, NULL, 0);
- waitpid(pidSSec, NULL, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement