#include #include const char *cmd1[] = { "/bin/ps", "-e", 0 }; const char *cmd2[] = { "/usr/bin/wc", "-l", 0 }; int fd[2]; //ipc-shell-2.c void runpipe() { int pid; switch (pid = fork()) { case 0: dup2(fd[0], 0); close(fd[1]); execvp(cmd2[0], cmd2); perror(cmd2[0]); default: dup2(fd[1], 1); close(fd[0]); execvp(cmd1[0], cmd1); perror(cmd1[0]); break; case -1: perror("fork"); exit(1); } } int main() { int pid, status; pipe(fd); switch (pid = fork()) { case 0: runpipe(); exit(0); default: wait(); break; case -1: perror("fork"); exit(1); } exit(0); }