#include #include int main() { int p, s, comm[2]; printf("step 1\n"); pipe(comm); p = fork(); if (p == 0) { close(1); dup(comm[1]); execlp("ls", "ls", "-l", NULL); fprintf(stderr, "execlp failed\n"); exit(1); } char line[1000]; while (1) { int r = read(comm[0], line, 1000); if (r <= 0) break; printf("received %s\n", line); } p = wait(& s); printf("subprocess %d finished, status %d\n", p, s); printf("step 2\n"); }