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

Steve O'Hara-Smith steve at
Wed Jan 8 16:15:52 UTC 2020

On Wed, 08 Jan 2020 07:30:12 -0800
"Ronald F. Guilmette" <rfg at> 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

Steve O'Hara-Smith <steve at>

More information about the freebsd-questions mailing list