
April 23rd, 2003, 09:55 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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().
|