April 23rd, 2003, 09:44 PM
Hi I have two programs, I want the output of one to be the input of the other, only it is not happening. Right now I forktwice to protect the main program if the other two exec programs crash nothing bad happens. Can anyone help? Thanks!
April 23rd, 2003, 09:55 PM
I'm looking at page 526 of O'Reilly's "Understanding the Linux Kernel", "Using a Pipe".
In their description, the parent uses the pipe() system call, then forks twice and closes the pipe's file descriptors (3 for the read channel, 4 for the write channel).
The first child (read "left side of the pipe") does a dup2(4,1) to make the pipe's write channel its stdout (I guess it should have closed stdout first). Then it closes descriptors 3 & 4 and calls execve().
The second child (read "right side of the pipe") similarly does a dup2(3,0) to make the read channel its stdin. Then it closes descriptors 3 & 4 and calls execve().
April 23rd, 2003, 10:27 PM
I am doing that only using execvp but it just kind of sits there
no idea what is going on....
April 23rd, 2003, 11:42 PM
I'm not sure that you're fork statements are happening correctly. Make sure to check the return values on the fork statement. Also be sure to terminate your children, you'll run out of avaiable processes.
Hope that helps...:)
April 24th, 2003, 10:22 AM
And if you want to use trace statements for the child processes to report their status, you should still have stderr to work with.
April 24th, 2003, 12:21 PM