Date: Wed, 8 Jan 2020 16:15:44 +0000 From: Steve O'Hara-Smith <steve@sohara.org> To: "Ronald F. Guilmette" <rfg@tristatelogic.com> Cc: freebsd-questions@freebsd.org Subject: Re: Independence of file descriptor flags across forks (or lack thereof) Message-ID: <20200108161544.76f64dd6eb0d1edb134a5b0f@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: > File status flags and file access modes are associated with the > file description and do not affect other file descriptors that > refer to the same file with different open file descriptions. > > Why else would the authors of this standard have included such stilted > and, admittedly, imprecise language as that if they were NOT attempting > to say exactly what I have said? OK I can explain this: fd1 = open ("/some/file", O_RDONLY); fd2 = open ("/some/file", O_RDWR); Now I have two file descriptors referring to the same file with different file access modes. I can set flags on fd1 and fd2 independently. That is what the precisely phrased paragraph above is referring to. Each file descriptor (with values like 3) refers to a table which identifies the kernel data structure representing the open file. It is that kernel data structure that holds such things as the file position, mode, flags etc. Now if I fork this process then the table of open file descriptors gets copied so now two processes are sharing the same kernel data structures. -- Steve O'Hara-Smith <steve@sohara.org>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200108161544.76f64dd6eb0d1edb134a5b0f>