// A demonstration of unix pipes where the output of the parent
// program is redirected to the input of a child
#include <iostream>
#include <unistd.h>
using namespace std;
void parent_main();
void child_main();
int main(void) {
int p[2];
int i;
int pid;
//create the pipe
pipe(p);
//fork the process
pid = fork();
//set up the pipe
if(pid) {
//parent process does the writing
dup2(p[1], STDOUT_FILENO);
//close the unused side of the pipe
close(p[0]);
parent_main();
} else {
//child process does the reading
dup2(p[0], STDIN_FILENO);