#include #include #include #include #include int main(void) { pid_t childpid; int fd[2]; //file descriptor1 if (pipe(fd)==-1) { printf(" pipe failed \n" ); } childpid = fork(); if (childpid==0) { /* ls is the child */ if (dup2(fd[1] , 1) == -1) { perror("Failed to redirect stdout of ls"); } else { if (execl("/bin/cat", "cat", "sortthis.txt", NULL) == -1) { perror("catting test failed"); } } return 1; } if (dup2(fd[0], 0) == -1) /* word count is the parent */ perror("Failed to redirect stdin of sort"); else { if (execl("/bin/sort", "sort", "-r", NULL) == -1) { perror("could not sort anything"); } } return 1; }