From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=0.5 required=3.0 tests=BODY_8BITS,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 92FFB1F44D for ; Tue, 2 Apr 2024 16:21:08 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; secure) header.d=cs.wisc.edu header.i=@cs.wisc.edu header.a=rsa-sha256 header.s=csl-2018021300 header.b=bK2Z6jz7; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AB643858C32 for ; Tue, 2 Apr 2024 16:21:07 +0000 (GMT) Received: from smtpout2.cs.wisc.edu (smtpout2.cs.wisc.edu [128.105.6.54]) by sourceware.org (Postfix) with ESMTPS id C5BD23858D28 for ; Tue, 2 Apr 2024 16:20:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5BD23858D28 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=cs.wisc.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.wisc.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C5BD23858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=128.105.6.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712074848; cv=none; b=xNVuRz0n3dkY54YsZhPSvumZBYvkdiOXbPRx7+llwKBtMxOQVct5xWRdqSABtUqjGQfiWJUcRiDVKj9yBt/OzGMqg7ZpeKqAey9ps09c1LTOKC5ahTWSj11A04bYPhGKgww5ZbqUBiZ5d9B8IoF2ZR38eyKiPCDpHcMinS9YUdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712074848; c=relaxed/simple; bh=5lescR+N8Vm4QDpICbzINYUIDA1RV2PmfY7m0S6dE3Q=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UT4trjQRftO/0m+T2FEXRbnDjXL+fWCnNxVtmnPo67qPr056zW5IpyZjUaeEXxcujODdAsmVEK2OZCOoLDQJTug7pPQzkkY9/AtpEJIqsidHMgruxG//eRt3NcA8PIk5fDVziw0ZGTCNbVjBhFtOJ0+bTlK2KsiZ3mD10+kQGB4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from alumni.cs.wisc.edu (alumni.cs.wisc.edu [128.105.2.11]) by flint.cs.wisc.edu (8.14.7/8.14.4) with ESMTP id 432GKX9m024978; Tue, 2 Apr 2024 11:20:33 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 flint.cs.wisc.edu 432GKX9m024978 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.wisc.edu; s=csl-2018021300; t=1712074835; bh=AC3b58WB0oF4ivCJzCwzAxGikO0pvWgHMFyGm1/ZrHk=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=bK2Z6jz7fSWVQqmu9UFVC3vyKbuoDj1P44xL3ff7v+7hPLQcwVJnoWqG2umg2IX9V mCOk2jmw8YgQT3/lMjwf+3el6FxrEjVUbighOVPmFB9vqrP5i6zq1typR7Kpoh54wE s2eoHZ5piZQN1YgliWMyBjQc7zBNh0dkuaUtOMAErXzZP3g9+AAuVKeHvQyO1Wg6Dy JeJIQ8ViHGdvRL51TP7rtJFxzPP3Sd0gC7uo2RFerq9Xva+kgCy8DImI5SKDWo8kHT t0WrrSCdVggEx6/lwTtKPTU3AVTLGYxhSvIMg4XKuEdaO4ipqxVPYqaC2e6eigwv6i Ga32o117NBQwQ== Received: from localhost (localhost.localdomain [127.0.0.1]) by alumni.cs.wisc.edu (Postfix) with ESMTP id 405491E0713; Tue, 2 Apr 2024 11:20:32 -0500 (CDT) Date: Tue, 2 Apr 2024 11:22:15 -0500 (CDT) From: Carl Edquist To: Chet Ramey cc: Zachary Santer , bug-bash , libc-alpha@sourceware.org Subject: Re: Examples of concurrent coproc usage? In-Reply-To: <1878a356-3eb4-4818-85d9-96531bd35bc9@case.edu> Message-ID: References: <9831afe6-958a-fbd3-9434-05dd0c9b602a@draigBrady.com> <317fe0e2-8cf9-d4ac-ed56-e6ebcc2baa55@cs.wisc.edu> <8c490a55-598a-adf6-67c2-eb2a6099620a@cs.wisc.edu> <88a67f36-2a56-a838-f763-f55b3073bb50@lando.namek.net> <1878a356-3eb4-4818-85d9-96531bd35bc9@case.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=-1463761075171154472417120749376399 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463761075171154472417120749376399 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT On Mon, 1 Apr 2024, Chet Ramey wrote: > On 4/1/24 3:24 PM, Chet Ramey wrote: >> On 3/14/24 5:58 AM, Carl Edquist wrote: >> >>> Well, *without multi-coproc support*, here's a simple wc example; first >>> with a single coproc: >>> >>>      $ coproc WC { wc; } >>>      $ exec {WC[1]}>&- >>>      $ read -u ${WC[0]} X >>>      $ echo $X >>>      0 0 0 >>> >>> This works as expected. >>> >>> But if you try it with a second coproc (again, without multi-coproc >>> support), the second coproc will inherit copies of the shell's read and >>> write pipe fds to the first coproc, and the read will hang (as described >>> above), as the first coproc doesn't see EOF: >>> >>>      $ coproc WC { wc; } >>>      $ coproc CAT { cat; } >>>      $ exec {WC[1]}>&- >>>      $ read -u ${WC[0]} X >>> >>>      # HANGS >>> >>> >>> But, this can be observed even before attempting the read that hangs. >> >> Let's see if we can tackle these one at a time. This seems like it >> would be pretty easy to fix if a coproc closed the fds corresponding >> to an existing coproc in the child after the fork. That wouldn't >> really change anything regarding how scripts have to manually manage >> multiple coprocs, but it will prevent the shell from hanging. >> > > I sent this before I was ready. This would be equivalent to changing the > commands to use > > coproc CAT { exec {WC[0]}<&- {WC[1]}>&- ; cat; } > > but the script writer wouldn't have to manage it. Agreed. And just to note two things (in case it wasn't clear) - (1) the above example that hangs is with the default bash, compiled _without_ multi-coproc support; and (2): > This seems like it would be pretty easy to fix if a coproc closed the > fds corresponding to an existing coproc in the child after the fork the forked coproc has to close its fds to/from _all_ other existing coprocs (as there can be several). Carl ---1463761075171154472417120749376399--