From owner-freebsd-questions@freebsd.org Thu Jan 9 05:30:09 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C767F229B96 for ; Thu, 9 Jan 2020 05:30:09 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 47tZSd06BHz4dN9 for ; Thu, 9 Jan 2020 05:30:08 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: by segfault.tristatelogic.com (Postfix, from userid 1237) id 4A3EA4E71D; Wed, 8 Jan 2020 21:30:00 -0800 (PST) From: "Ronald F. Guilmette" To: freebsd-questions@freebsd.org Subject: Re: Independence of file descriptor flags across forks (or lack thereof) In-Reply-To: <20200108161544.76f64dd6eb0d1edb134a5b0f@sohara.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8430.1578547799.1@segfault.tristatelogic.com> Date: Wed, 08 Jan 2020 21:30:00 -0800 Message-ID: <8433.1578547800@segfault.tristatelogic.com> X-Rspamd-Queue-Id: 47tZSd06BHz4dN9 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of rfg@tristatelogic.com designates 69.62.255.118 as permitted sender) smtp.mailfrom=rfg@tristatelogic.com X-Spamd-Result: default: False [-5.38 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[tristatelogic.com]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:14051, ipnet:69.62.128.0/17, country:US]; IP_SCORE(-3.08)[ip: (-8.08), ipnet: 69.62.128.0/17(-4.04), asn: 14051(-3.21), country: US(-0.05)] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jan 2020 05:30:09 -0000 In message <20200108161544.76f64dd6eb0d1edb134a5b0f@sohara.org>, Steve O'Hara-Smith 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