#include <stdio.h>
#include <err.h>
#include <unistd.h>
static char buf[65536];
int main()
{
pid_t child;
int status;
int p[2],q[2];
int i;
char ch;
if (pipe(p) == -1)
err(1,"pipe");
if (pipe(q) == -1)
err(1,"pipe");
child = fork();
if (child == -1)
err(1,"fork");
if (child == 0) {
close(p[0]);
close(q[1]);
i = 0;
while (i++<1000000 && read(0,buf,sizeof(buf)) == sizeof(buf)) {
write(p[1],&ch,1);
if (read(q[0],&ch,1) != 1)
break;
}
_exit(0);
}
close(p[1]);
close(q[0]);
while (read(p[0],&ch,1) == 1) {
write(q[1],&ch,1);
}
wait(&status);
return 0;
}