From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 10173 invoked from network); 11 Mar 2020 07:03:33 -0000 Received-SPF: pass (minnie.tuhs.org: domain of minnie.tuhs.org designates 45.79.103.53 as permitted sender) receiver=inbox.vuxu.org; client-ip=45.79.103.53 envelope-from= Received: from unknown (HELO minnie.tuhs.org) (45.79.103.53) by inbox.vuxu.org with ESMTP; 11 Mar 2020 07:03:33 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 64F399BCD7; Wed, 11 Mar 2020 17:03:28 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id E5A549BB47; Wed, 11 Mar 2020 17:03:04 +1000 (AEST) Received: by minnie.tuhs.org (Postfix, from userid 112) id 2940D9BB47; Wed, 11 Mar 2020 17:03:02 +1000 (AEST) Received: from freefriends.org (freefriends.org [96.88.95.60]) by minnie.tuhs.org (Postfix) with ESMTPS id 177AF9BB46 for ; Wed, 11 Mar 2020 17:03:01 +1000 (AEST) X-Envelope-From: arnold@skeeve.com Received: from freefriends.org (freefriends.org [96.88.95.60]) by freefriends.org (8.14.7/8.14.7) with ESMTP id 02B72xUK023434 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2020 01:03:00 -0600 Received: (from arnold@localhost) by freefriends.org (8.14.7/8.14.7/Submit) id 02B72xqj023433; Wed, 11 Mar 2020 01:02:59 -0600 From: arnold@skeeve.com Message-Id: <202003110702.02B72xqj023433@freefriends.org> X-Authentication-Warning: frenzy.freefriends.org: arnold set sender to arnold@skeeve.com using -f Date: Wed, 11 Mar 2020 01:02:59 -0600 To: tuhs@minnie.tuhs.org, gtaylor@tnetconsulting.net References: <20200306224431.D226C18C080@mercury.lcs.mit.edu> <1fab6a1a-ccfb-02cc-c23e-1a0d8c9e954a@spamtrap.tnetconsulting.net> <202003100729.02A7Tsg0002007@freefriends.org> <4fb5b7ab-03a4-df64-d25b-8be587b6a17b@spamtrap.tnetconsulting.net> In-Reply-To: <4fb5b7ab-03a4-df64-d25b-8be587b6a17b@spamtrap.tnetconsulting.net> User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [TUHS] First appearance of named pipes X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" Hi Grant. Grant Taylor via TUHS wrote: > The larger more onerous question is could I leverage exec to alter where > file descriptors 0 (STDIN), 1 (STDOUT), and 2 (STDERR) are set to, > including changing 1 to the value of a FIFO, and 0 of a subsequent > command to also be the value of the FIFO, thus have pipe like behavior > between two commands without using a pipe or redirection as in ">". There's nothing preventing you from doing that. After the fork() and before the exec(), just close() and dup() the relevant fds in the right order and you're set. > This has also gotten me to wonder about the possibility of having > multiple commands output to a file descriptor; 1 / 2 / other, that is > input to a separate command. Sort of the opposite of tee, in a manner > of speaking. I'll try to articulate: > > $ mkfifo test.fifo > $ exec 3>&1 > $ exec 1> test.fifo > $ for l in {a..z}; do echo $l; sleep 1; done & > $ for L in {A..Z}; do echo $L; sleep 1; done & > $ for n in {1..100}; do echo $n; sleep 1; done & > $ exec 1>&3 > $ cat test.fifo I don't think that this is any different from: (for l in {a..z}; do echo $l; sleep 1; done & for L in {A..Z}; do echo $L; sleep 1; done & for n in {1..100}; do echo $n; sleep 1; done &) | cat which reduces to: (for l in {a..z}; do echo $l; sleep 1; done & for L in {A..Z}; do echo $L; sleep 1; done & for n in {1..100}; do echo $n; sleep 1; done &) > /some/file (You might want to background that whole mess given that the final pipeline will sleep for 100 seconds.) > This seems special to me in that I have three processes (for loops) > writing into what is effectively the same pipe. It's not any different than calling `stty -tostop' and then simply backgrounding the three loops at the terminal. Try it! (This is the beauty of the Unix model, an fd is just a data sink, we don't care where it goes.) > I would be very eager to learn from anyone who is willing to teach me > pointers. :-) At the cost of tooting my own horn, I recommend my book "Linux Programming by Example: The Fundamentals", which, despite the "Linux" in the title, covers basic Unix programming, including file descriptor manipulation of the sort under discussion here. HTH, Arnold