Independence of file descriptor flags across forks (or lack thereof)

Steve O'Hara-Smith steve at sohara.org
Wed Jan 8 16:05:05 UTC 2020


On Wed, 08 Jan 2020 07:30:12 -0800
"Ronald F. Guilmette" <rfg at tristatelogic.com> wrote:

> In message <20200108114244.b431a9ae0170ec947e6fb7d8 at sohara.org>, 
> Steve O'Hara-Smith <steve at sohara.org> wrote:
> 
> >> that are currently open in the parent process, the child would also get
> >> its own independent copy of the system-maintained "flags word" for each
> >> of those inherited file descriptor copies.
> >
> >	The fork manpage tells you that the descriptors reference the
> >	same
> >underlying object. It is that object (the open file) which holds the
> >"flags word".
> 
> I am not persuaded.

	From man open:
-----------------------------------------
RETURN VALUES
     If successful, open() and openat() return a non-negative integer,
termed a file descriptor.  They return -1 on failure, and set errno to
indicate the error.
-----------------------------------------

	That's pretty clear - the file descriptor is the integer returned
by open.

	From man fork()
-----------------------------------------
           •   The child process has its own copy of the parent's
descriptors, except for descriptors returned by kqueue(2), which are not
inherited from the parent process.  These descriptors reference the same
underlying objects,
-----------------------------------------

	The underlying objects are the kernel data structures with all the
flags, seek position and so forth.

-- 
Steve O'Hara-Smith <steve at sohara.org>


More information about the freebsd-questions mailing list