#include <stdio.h>
#include <unistd.h>

void error(char *msg)
{
     perror(msg);
     exit(1);
}

int main()
{
    int p[2], retval;
    retval = pipe(p);
    if (retval < 0) error("pipe");
    retval=fork();
    if (retval < 0) error("forking");
    if (retval==0) { /* child */
       dup2(p[1],1); /* redirect stdout to pipe */
       close(p[0]);  /* don't permit this 
             process to read from pipe */
       execl("/bin/ls","ls","-l",NULL);
       error("Exec of ls");
    }
    /* if we get here, we are the parent */ 
     dup2(p[0],0); /*redirect stdin to pipe*/
     close(p[1]);  /* don't permit this 
                  process to write to pipe */
     execl("/bin/more","more",NULL);
     error("Exec of more");
     return 0;
}
