Hi
I am creating a program that can support piping between any number of processes. For 2 processes, you create 1 pipe, and use it between them.
However, for 3 or more pipes, this method will not work because of writing to a pipe while you still need the old one. Example:
http://img8.imageshack.us/img8/3145/pipesf.png
If you write to pipe[1] again (the red part), it will overwrite the previously written information, won't it?
What is the proper way to do this?
-------------------------
I have found that you can just create 1000 pipes or something like in the example below:
However, since I need to be able to support ANY number of pipes, and not just 2 or 3, I do not want to do this.Code:http://www.cs.loyola.edu/~jglenn/702/S2005/Examples/dup2.html int pipes[4]; pipe(pipes); // sets up 1st pipe pipe(pipes + 2); // sets up 2nd pipe // we now have 4 fds: // pipes[0] = read end of cat->grep pipe (read by grep) // pipes[1] = write end of cat->grep pipe (written by cat) // pipes[2] = read end of grep->cut pipe (read by cut) // pipes[3] = write end of grep->cut pipe (written by grep)
Does anyone know how this can be achieved properly?
Can I do something like this?
Anyone have any insight?Code:int old_write_pipe = mypipes[1]; // save the old write pipe int new_write_pipe; // new write pipe mypipes[1] = new_write_pipe; // replace the old write pipe in the array with a new file descriptor pipe(mypipes);



LinkBack URL
About LinkBacks




