Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!ut-sally!husc6!panda!teddy!jpn
From: jpn@teddy.UUCP (John P. Nelson)
Newsgroups: comp.unix.questions
Subject: Re: Fork and Join, Pipe in C
Message-ID: <4167@teddy.UUCP>
Date: Mon, 6-Jul-87 13:44:04 EDT
Article-I.D.: teddy.4167
Posted: Mon Jul  6 13:44:04 1987
Date-Received: Tue, 7-Jul-87 06:04:13 EDT
References: <7737@brl-adm.ARPA> <1186@ius2.cs.cmu.edu>
Reply-To: jpn@teddy.UUCP (John P. Nelson)
Organization: GenRad, Inc., Concord, Mass.
Lines: 23

>On os9, which has the create_process os9fork() call rather than a unix-like
>fork (error checking omited for simplicity):
>
>pipe = open("/pipe", S_IREAD | S_IWRITE);
>temp = dup(1);
>close(1);
>dup(pipe);
>os9fork(...);
>close(1);
>dup(temp);
>close(temp);

But this leaves extra file descriptors open in the child task!  By my
calculation, extra descriptors in the child task are "pipe", and
"temp".  You really want to CLOSE those descriptors in the child task,
but not in the parent task.

Obviously, there can be workarounds:  CLOSE_ON_EXEC information on a
per-descriptor basis, or a convention in all tasks to close all
descriptors above 2 before calling main().  The fundamental point is
unchanged, however, and that is that there is often a need to do some
extra operations between the logical "fork" into two processes, and
the "exec" of a new program image.