I am not very sure how to create a pipe between two child processes. This is the way I did it:
pipe(&fd[0]); //Create a pipe
pr
The best answer I can give is Beej's Guide to Unix IPC.
(Peek at section 4.3, where he gives a very similar example to the question you asked...)
In the child process 1 setup, close(STD_INPUT); dup(fd[1]);
will duplicate fd[1]
to the lowest available descriptor, which is 0 (STD_INPUT
) rather than 1 (STD_OUTPUT
). Don't you want to close STD_OUTPUT
instead? Also, I'd recommend dup2(fd[1], STD_OUTPUT)
in place of this sequence; it will do what you want and is more clear anyway.
Likewise child process 2 uses STD_OUTPUT
where you probably want STD_INPUT
.