/*
 * A simple pipe example.
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

main()
{
  int pid;
  int fd[2];

  // Create the pipe.
  pipe(fd);

  // Create the child.
  pid=fork();

  // Check for errors
  if (pid < 0) {
    fprintf(stderr, "fork() failed.  Exiting.\n");
    exit(1);
  }
  // Parent
  else if (pid) {
    int ch;
    int status;
    close(fd[1]);
    dup2(fd[0],STDIN_FILENO);
    while ((ch = getc(stdin)) != EOF) {
      putc('[', stdout);
      putc(ch, stdout);
      putc(']', stdout);
    }
    wait(&status);
    exit(0);
  }

  // Child
  else {
    close(fd[0]);
    dup2(fd[1],STDOUT_FILENO);
    printf("This is a test.\n");
    printf("This is another test.\n");
    printf("%d", 23);
    exit(0);
  }
} // main()
