Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <limits.h>
- main()
- {
- int fd[2];
- int n=0, i;
- pipe(fd);
- if (fork() == 0) {
- /* Child process */
- close(1); dup(fd[1]) ; /* Redirect the stdout of this process to the pipe.*/
- close(fd[0]); /* This process will not read from the pipe in this example. Hence we close fd[0].*/
- execlp("ls","ls","-l",(char *)NULL);
- } else {
- /* Parent process */
- close(0); dup(fd[0]) ; /* Redirect the stdin of this process to the pipe */
- close(fd[1]);/* In this example, this process will not write into the pipe. Hence we close fd[1].*/
- execlp("wc","wc","-c",(char *)NULL);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement