Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- int main(int argc, char **argv) {
- if (argc != 3) {
- return 1;
- }
- int pipes[2];
- if (pipe(pipes) == -1) {
- return 1;
- }
- int pid = fork();
- if (pid == -1) {
- exit(1);
- }
- if (!pid) {
- dup2(pipes[1], 1);
- close(pipes[0]);
- close(pipes[1]);
- execlp(argv[1], argv[1], NULL);
- _exit(1);
- }
- pid = fork();
- if (pid == -1) {
- exit(1);
- }
- if (!pid) {
- dup2(pipes[0], 0);
- close(pipes[0]);
- close(pipes[1]);
- execlp(argv[2], argv[2], NULL);
- _exit(1);
- }
- close(pipes[0]);
- close(pipes[1]);
- wait(NULL);
- wait(NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement