|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
pipe!
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!
|
|
#2
|
||||
|
||||
|
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(). |
|
#3
|
|||
|
|||
|
hmm
I am doing that only using execvp but it just kind of sits there
no idea what is going on.... |
|
#4
|
|||
|
|||
|
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... ![]() |
|
#5
|
||||
|
||||
|
And if you want to use trace statements for the child processes to report their status, you should still have stderr to work with.
|
|
#6
|
|||
|
|||
|
Thanks!
I got it to work!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > pipe! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|