Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Jan 2020 16:04:53 +0000
From:      Steve O'Hara-Smith <steve@sohara.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: Independence of file descriptor flags across forks (or lack thereof)
Message-ID:  <20200108160453.6b9d3c31e8afb47b3a94ae2a@sohara.org>
In-Reply-To: <99921.1578497412@segfault.tristatelogic.com>
References:  <20200108114244.b431a9ae0170ec947e6fb7d8@sohara.org> <99921.1578497412@segfault.tristatelogic.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 08 Jan 2020 07:30:12 -0800
"Ronald F. Guilmette" <rfg@tristatelogic.com> wrote:

> In message <20200108114244.b431a9ae0170ec947e6fb7d8@sohara.org>, 
> Steve O'Hara-Smith <steve@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@sohara.org>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200108160453.6b9d3c31e8afb47b3a94ae2a>