Date: Wed, 08 Jan 2020 21:30:00 -0800 From: "Ronald F. Guilmette" <rfg@tristatelogic.com> To: freebsd-questions@freebsd.org Subject: Re: Independence of file descriptor flags across forks (or lack thereof) Message-ID: <8433.1578547800@segfault.tristatelogic.com> In-Reply-To: <20200108161544.76f64dd6eb0d1edb134a5b0f@sohara.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <20200108161544.76f64dd6eb0d1edb134a5b0f@sohara.org>, Steve O'Hara-Smith <steve@sohara.org> wrote: > 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. All I can say is that the kernel implementors of both FreeBSD and also Linux seem to agree with your viewpoint. I myself am not persuaded that the two file descriptors that exist after a fork should behave any differently from the two in your example above, but they do, so I guess I just have to deal with it. Regards, rfg
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8433.1578547800>