[comp.unix.wizards] Parent and child processes and files

hsiegel@cvbnet.UUCP (Howard Siegel 4-2390 x4064) (12/24/89)

Howdy, folks.

Here's a problem I'm trying to lick in SunOS 4.0.3.

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.

I believe this scheme to be workable but baroque.  Among the problems I
envision is having to provide other wrappers around the read/write (etc)
functions as well, to keep track of the current access point in the
files.

I hope someone out there in netland is able to suggest a simpler and
more elegant solution.  Failing that, I'd appreciate suggestions as to
points I may have overlooked in my sketched solution above.

As always, thanks in advance.  If people express interest, I'll post a
summary of whatever responses I may get.


Howard Siegel                   hsiegel@piano.prime.com
Prime/Computervision            hsiegel@primerd.prime.com
Bedford, Mass.                  hsiegel%piano.prime.com@RELAY.CS.NET
(617) 275-1800 x4064            cvbnet!hsiegel@primerd.prime.com

lm@snafu.Sun.COM (Larry McVoy) (12/29/89)

In article <296@cvbnet.Prime.COM> hsiegel@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@sun.com