From owner-freebsd-questions@freebsd.org Wed Jan 8 16:15:52 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 4EEEC1F370D for ; Wed, 8 Jan 2020 16:15:52 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) Received: from s1-b0c6.socketlabs.email-od.com (s1-b0c6.socketlabs.email-od.com [142.0.176.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 47tDr73fXLz3HGR for ; Wed, 8 Jan 2020 16:15:51 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) DKIM-Signature: v=1; a=rsa-sha256; d=email-od.com;i=@email-od.com;s=dkim; c=relaxed/relaxed; q=dns/txt; t=1578500152; x=1581092152; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to:message-id:subject:cc:to:from:date:x-thread-info; bh=4I1OWDvNeQTVOKU4yW1diV/Ri/fPIqa/5FNDxc5na7k=; b=egfDY2dzWAK6q2EubofK4Wx8wXgNUp3fF9Dml5v24NzLsG6hz+PxMW3KvRJa+QJ3fa231bOlxYOOh+IG0vzl4DsOkih5teo9u1laeGa3jDUr+OWYgFTij535uVTF/XdDchrPv7IFFR8BFF5ZeJPPhbxi2IQFE9pNPCSzraVzv4g= X-Thread-Info: NDI1MC4xMi42YTAwMDAwMjM4ZTcwNS5mcmVlYnNkLXF1ZXN0aW9ucz1mcmVlYnNkLm9yZw== Received: from r1.us-west-2.aws.in.socketlabs.com (r1.us-west-2.aws.in.socketlabs.com [142.0.190.1]) by mxsg2.email-od.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Wed, 8 Jan 2020 11:15:48 -0500 Received: from smtp.lan.sohara.org (EMTPY [185.202.17.215]) by r1.us-west-2.aws.in.socketlabs.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Wed, 8 Jan 2020 11:15:46 -0500 Received: from [192.168.63.1] (helo=steve.lan.sohara.org) by smtp.lan.sohara.org with smtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1ipDzk-0002AW-DL; Wed, 08 Jan 2020 16:15:44 +0000 Date: Wed, 8 Jan 2020 16:15:44 +0000 From: Steve O'Hara-Smith To: "Ronald F. Guilmette" 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> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; amd64-portbld-freebsd12.0) X-Clacks-Overhead: "GNU Terry Pratchett" Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 47tDr73fXLz3HGR X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=email-od.com header.s=dkim header.b=egfDY2dz; dmarc=none; spf=pass (mx1.freebsd.org: domain of 4250.10.freebsd-questions=freebsd.org@email-od.com designates 142.0.176.198 as permitted sender) smtp.mailfrom=4250.10.freebsd-questions=freebsd.org@email-od.com X-Spamd-Result: default: False [-1.82 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.96)[-0.959,0]; R_DKIM_ALLOW(-0.20)[email-od.com:s=dkim]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:142.0.176.0/20:c]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[sohara.org]; FORGED_SENDER_VERP_SRS(0.00)[]; NEURAL_HAM_LONG(-0.99)[-0.991,0]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[email-od.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[198.176.0.142.list.dnswl.org : 127.0.15.0]; ENVFROM_VERP(0.00)[]; IP_SCORE(0.13)[ip: (-0.35), ipnet: 142.0.176.0/22(0.67), asn: 7381(0.40), country: US(-0.05)]; FORGED_SENDER(0.00)[steve@sohara.org,4250.10.freebsd-questions=freebsd.org@email-od.com]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:7381, ipnet:142.0.176.0/22, country:US]; FROM_NEQ_ENVFROM(0.00)[steve@sohara.org,4250.10.freebsd-questions=freebsd.org@email-od.com]; MID_RHS_MATCH_FROM(0.00)[] 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: Wed, 08 Jan 2020 16:15:52 -0000 On Wed, 08 Jan 2020 07:30:12 -0800 "Ronald F. Guilmette" 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