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

#define READ 0
#define WRITE 1
#define is_parent(P) P > 0

void paginacao() {
  pid_t new_proc;
  int fd[2];

  pipe(fd);
  if (is_parent(fork())) {
    char buf[100];
    int n;
    close(fd[READ]);
    for (n=1; n<=100; n++) {
      sprintf(buf, "Linha %d\n", n);
      write(fd[WRITE], buf, strlen(buf)); 
    }
    close(fd[WRITE]);
    wait(NULL);
  } else { // filho
    close(fd[WRITE]);
    dup2(fd[READ], STDIN_FILENO);
    close(fd[READ]);
    execlp("more","more",NULL);
    printf("FILHO: falha no execlp!\n");
  }
  return;
}

main() {
  paginacao();
  exit(0);
}
