Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/wait.h>
- #include <sys/ipc.h>
- #include <sys/sem.h>
- #include <sys/shm.h>
- #include <sys/msg.h>
- #include <sys/types.h>
- int
- main (int argc, char *argv[])
- {
- int pipefd12[2];
- pipe(pipefd12);
- if (!fork()) {
- close(pipefd12[0]);
- dup2(pipefd12[1], 1);
- close(pipefd12[1]);
- execlp(argv[1], argv[1], NULL);
- exit(0);
- }
- close(pipefd12[1]);
- int pipefd23[2];
- pipe(pipefd23);
- if (!fork()) {
- close(pipefd23[0]);
- dup2(pipefd12[0], 0);
- close(pipefd12[0]);
- dup2(pipefd23[1], 1);
- close(pipefd23[1]);
- if (!fork()) {
- int fd = open(argv[5], O_TRUNC | O_WRONLY | O_CREAT, 0600);
- dup2(fd, 2);
- close(fd);
- execlp(argv[2], argv[2], NULL);
- exit(0);
- }
- int status;
- wait(&status);
- if (WIFEXITED(status) && !WEXITSTATUS(status)) {
- if (!fork()) {
- execlp(argv[3], argv[3], NULL);
- exit(0);
- }
- wait(NULL);
- }
- exit(0);
- }
- close(pipefd12[0]);
- close(pipefd23[1]);
- if (!fork()) {
- dup2(pipefd23[0], 0);
- close(pipefd23[0]);
- execlp(argv[4], argv[4], NULL);
- exit(0);
- }
- close(pipefd23[0]);
- while (wait(NULL) != -1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement