// A demonstration of unix pipes where string are written
// to the input of a child
#include <iostream>
#include <unistd.h>
#include <cstring>
#include <string>
using namespace std;
void parent_main(int fd);
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) {
//close the unused side of the pipe
close(p[0]);
parent_main(p[1]);
} else {
//child process does the reading
dup2(p[0], STDIN_FILENO);