Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/stat.h>
- int main() {
- int pipefd[2], child_pid, grand_child;
- pipe(pipefd);
- child_pid = fork();
- if (child_pid) {
- waitpid(child_pid, NULL, 0);
- /* Parent */
- grand_child = fork();
- if (!grand_child) {
- dup2(pipefd[0], STDIN_FILENO);
- close(pipefd[0]);
- close(pipefd[1]);
- execlp("cat", "cat", NULL);
- } else {
- waitpid(grand_child, NULL, 0);
- }
- } else {
- /* Child */
- dup2(pipefd[1], STDOUT_FILENO);
- close(pipefd[1]);
- close(pipefd[0]);
- execlp("ls", "ls", NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement