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