Parent and child processes and files

Larry McVoy lm at snafu.Sun.COM
Fri Dec 29 18:39:44 AEST 1989


In article <296 at cvbnet.Prime.COM> hsiegel at cvbnet.UUCP (Howard Siegel 4-2390 x4064) writes:
>I have a situation in which a parent process spawns children at
>request.  Obviously, any file open at the time a child is spawned is
>shared between parent and child.  After spawning a child, the parent
>waits until the child dies before resuming activity.
>
>However, suppose that the child process opens or closes a file on
>behalf of its parent.  For reasons unhelpful to elaborate, it is
>necessary for the parent to know the files that particular child
>opened or closed, in order to provide them to other children.
>
>The only feasible solution I've come up with so far is to equip the
>file opening and closing routines with wrappers which will store the
>names, open mode, status, and file descriptors for all files opened and
>closed in a table in shared memory that the parent shares with all its
>children.  When a child dies, the parent then scans the table, opening
>and closing files appropriately.

Gag me.  I'll bet all you need are file descriptors, not the file names.
If that's the case, have that parent get a pipe before it forks.  The
parent can select on the read end, the child can pass up the fd, and the
parent can pass it through to all the other pipes.  You need to be on
a BSD based system.

	 What I say is my opinion.  I am not paid to speak for Sun.

Larry McVoy, Sun Microsystems                          ...!sun!lm or lm at sun.com



More information about the Comp.unix.wizards mailing list