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

enum { buf_size = 4096 };

enum exit_codes {
    exit_success,
    exit_failure,
    exit_arguments,
    exit_process,
    exit_signal,
    exit_file
};

static const char msg[] = "Hello there\n";

static void terminate(const char *msg, int code)
{
    perror(msg);
    exit(code);
}

int main()
{
    int fd[2];
    int p1, p2, rc;
    char buf[buf_size];

    pipe(fd);

    p1 = fork();
    if (p1 == -1)
        terminate("fork", exit_process);
    if (p1 == 0) {
        close(fd[0]);
        write(fd[1], msg, sizeof(msg)-1);
        exit(0);
    }

    p2 = fork();
    if (p2 == -1)
        terminate("fork", exit_process);
    if (p2 == 0) {
        close(fd[1]);
        rc = read(fd[0], buf, buf_size);
        exit(0);
    }
    close(fd[0]);
    close(fd[1]);
    return 0;
}
