I am now learning about the process programming on C++, and I have a question now about the fork() and pipe().
I need to run two programs in parallel, and program A's standard output connected to B's standard input, and B's standard output connected to A's standard input.
For this particular question, am I supposed to have 2 pipes? How can I run them recursively? Could any of you can provide me an example? Thank you very much.
EDIT: I got something like that but it didn't work.
int pipe1[2];
int pipe2[2];
pipe(pipe1);
pipe(pipe2);
pid = fork();
if (pid == 0) {
dup2(pipe1[0], 0);
close(pipe1[1]);
close(pipe1[0]);
dup2(pipe2[1], 1);
close(pipe2[0]);
close(pipe2[1]);
execvp(A[0],A);
} else {
dup2(pipe2[0], 0);
close(pipe2[0]);
close(pipe2[1]);
dup2(pipe1[1], 1);
close(pipe1[1]);
close(pipe1[0]);
execvp(B[0],B);
}