int main(void) { pid_t childpid; int fd[2]; if (( pipe(fd) == -1) || ((childpid = fork() ) == -1)) { /* setup the pipeline*/ perror("Failed to setup pipeline"); return 1; } if (childpid==0) { /* ls is the child */ if (dup2(fd[1] , 1) == -1) perror("Failed to redirect stdout of ls"); else if (( close(fd[1]) == -1) || ( close(fd[0]) == -1)) perror("Failed to close extra pipe descriptors on ls"); else { printf("HI\n"); } return 1; } if (dup2(fd[0], 0) == -1) /* word count is the parent */ perror("Failed to redirect stdin of sort"); else if ((close(fd[1]) == -1) || (close(fd[0]) == -1)) perror("Failed to close extra pipe file descriptors on sort"); else { //Prints 1 1 3 (the 3 is for HI + string terminator. But what are the 1 and 1 ?) execl("/usr/bin/wc", "-cl", NULL); perror("Failed to exec word count"); } return 1; }