tags:

views:

308

answers:

2

Hello everyone, I am trying to execute a program from a parent using execl. I do the normal pipe setup and fork. Here is the trick... I need my children (there can be an arbitrary number of children) to all communicate with the parent.

Program "A" (parent) creates pipe forks and execl into "B" (child). In the main() function of program B I need to be able to read and write to the pipe.

Is there any way to access my pipe file descriptors in the child process after the excel takes over and executes my child process?

Thank you, ~Eric

A: 

Read Beej's Guide to Unix Interprocess Communication ( you can find it at http://beej.us/guide/ ), particularly section 4.

pmg
+1  A: 

execl(3) has no effect on file descriptors, with one exception

It is possible to mark a file descriptor close-on-exec with fcntl(2), but generally the various flavors of execve(2) have no effect on open file descriptors and they remain open in children.

DigitalRoss
Thank you. I found that passing the "in" and "out" file descriptors of the pipe as arguments to program "B" did the trick.
EToreo