#include #include int main() { int p[2]; /* p is pointer to array of two ints */ int rc; rc = pipe( p ); printf( "%d %d\n", p[0], p[1] ); if ( rc < 0 ) { perror( "pipe() failed" ); return 1; } rc = fork(); /* create child */ if ( rc < 0 ) { perror( "fork() failed" ); return 1; } if ( rc == 0 ) { /* child */ dup2( p[1], 1 ); /* redirect stdout (1) to pipe */ close( p[0] ); /* don't let this child process access p[0] */ execlp( "/bin/ls", "ls", "-l", NULL ); } else /* parent */ { dup2( p[0], 0 ); /* redirect stdin (0) to pipe */ close( p[1] ); execlp( "/usr/local/bin/less", "less", NULL ); } return 0; }