#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(int argc, int *argv[]) {
  int pipefd[2] ;
  pipe(pipefd) ;

  // fprintf(stdout, "Read %d, Write %d\n", pipefd[0], pipefd[1]) ;

  int pid = fork() ;

  if (pid == 0) {
    char *const child_args[] = {
      "seq",
      "0",
      "10000",
      NULL
    } ;
    dup2(pipefd[1], 1) ;
    close(pipefd[1]) ;
    close(pipefd[0]) ;
    execve("/usr/bin/seq", child_args, (char * const*)NULL) ; 
    fprintf(stderr, "child failure!\n") ;
    exit(0) ;
  } else {
    char *const parent_args[] = {
      "grep",
      "235",
      NULL
    } ;
    dup2(pipefd[0], 0) ;
    close(pipefd[0]) ;
    close(pipefd[1]) ;
    execve("/bin/grep", parent_args, (char * const*)NULL) ;
    fprintf(stderr, "parent failure!\n") ;
    exit(0) ;
  }
}



