[comp.unix.questions] Child access to parent files opened AFTER fork/exec.

daveh@marob.MASA.COM (Dave Hammond) (10/28/88)

Given that a child process inherits the open files of its parent,
is there any way for the child to access a file opened by the
parent subsequent to the child being exec'd ?

As an example, the parent forks a subprocess who's task is to present
data (from files or pipelines) generated by the parent.  For each new
data stream, the parent and child exchange messages concerning the
origination of the data, the results of the presentation session, etc.

Because the child is exec'd only once, it must open and manage each file
or pipeline in question.  It would be beneficial to divorce the child from
the file/pipeline management tasks and allow it to simply regard its input as
stream data to be presented.  However, forking a new child for each new data
stream (just to inherit a file descriptor) is undesireable, as it would cause
a noticeable delay each time the child is invoked.

Dave Hammond
  UUCP: ...!uunet!masa.com!{marob,dsix2}!daveh
DOMAIN: daveh@marob.masa.com
----------------------------------------------------------------------------

guy@auspex.UUCP (Guy Harris) (10/29/88)

>Given that a child process inherits the open files of its parent,
>is there any way for the child to access a file opened by the
>parent subsequent to the child being exec'd ?

Yes.  It can reopen those files itself, assuming the files have a file
name, it knows the file name, and opening something with that name gives
it a descriptor for the same file (which needn't be true if the file is
a special file that refers to a "clone" device).

Alternatively, some UNIX IPC mechanisms, namely UNIX-domain sockets in
4.[23]BSD and "stream pipes" in System V Release 3.x, permit a process
to pass file descriptors to another process.