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=-1.0 required=3.0 tests=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 7D3B21F44D for ; Sat, 20 Apr 2024 22:03:04 +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=EYwureGV; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C97883858401 for ; Sat, 20 Apr 2024 22:03:03 +0000 (GMT) Received: from smtpout2.cs.wisc.edu (smtpout2.cs.wisc.edu [128.105.6.54]) by sourceware.org (Postfix) with ESMTPS id C85673858D34 for ; Sat, 20 Apr 2024 22:02:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C85673858D34 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 C85673858D34 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=1713650566; cv=none; b=Bhc1hljGvUsPTXqKK8jIDCUjo/9f6JK2b+pOkx6BFnuuH4AMWOxJEA8SrMFRNnCWA0JK0fC931U7rS5wPG7Uv9HwKA977nsP4k4Vo2o8+/m0O0VWjOVDk7CUfYGr+Z0xpzodnQW5NFuNvZcmaT2lemQGXcJo37kYF2ueDvnt+E0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713650566; c=relaxed/simple; bh=NqK7ao2vN7aY9NDNv0lXupiSJ4otzrUreyto7DQES2E=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=nkHzUsq8Q2IoEUk6wNIfsNvxEhYHlhLdqE8jweqhWhWkCSJgcLMEYez/2VsiAOftlNBbdaS2ypeGs/ZnVxt85R74ysAYWP21ggFxigbzUfZYOu01vHlX1N3XBH+30zxKLGW5QA62X5KKGULG1QbF40GsE8n18QGA9p9TyO5TRyU= 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 43KM2eJ6011125; Sat, 20 Apr 2024 17:02:40 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 flint.cs.wisc.edu 43KM2eJ6011125 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.wisc.edu; s=csl-2018021300; t=1713650560; bh=rYD7ntcaJ1u5idSXceSPVMOpmtP+XcIQNrPFn2M6Wc4=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=EYwureGVO3AxMveCsgxfQ1C9o/BWXEBtbjCbVDTYw0wZi3j8iWdZfQlF8o2ZSsZ2w LmW6g7tKCfvMGYBiY/TKCHWJoGUxlNdyDIrscO3w4+LOnwsDU8yLC7uGe8Kjlv43qd 3O9Ag7n57aJ2m158l5V0iIqyT2DXYg9u1ZbyUTG7xRJFSKGxWE0hbNbqYEg+pLILDO Hc4rek8Pu4J9onLqVHmEfvDaHfJ85tAeBxh292k2uC3Zflc3qvQicr2vhhaIqW7Leu +uuvw+pAW/xJ16lvz97DPNlyhEnuCt+WmUSkvkYNPRSwRgS4RnaXaZPoevCziMX8Uy WhvvW74TrH1Lw== Received: from localhost (localhost.localdomain [127.0.0.1]) by alumni.cs.wisc.edu (Postfix) with ESMTP id 96DD91E0849; Sat, 20 Apr 2024 17:02:39 -0500 (CDT) Date: Sat, 20 Apr 2024 17:04:27 -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: Message-ID: <2febc4ce-a9a8-d1a9-51c3-0ed5d1b20716@cs.wisc.edu> 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> <2791ad90-a871-474d-89dd-bc6b20cdd1f2@case.edu> <32bd9e76-24bc-4206-aa8a-8bcc817228b1@case.edu> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii 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 On Wed, 17 Apr 2024, Chet Ramey wrote: > On 4/15/24 1:01 PM, Carl Edquist wrote: >> >> Yet another point brought to light by the bcalc example relates to the >> coproc pid variable. The reset() function first closes the coproc >> pipe fds, then sleeps for a second to give the BC coproc some time to >> finish. >> >> An alternative might be to 'wait' for the coproc to finish (likely >> faster than sleeping for a second). > > If the coproc has some problem and doesn't exit immediately, `wait' > without options will hang. That's why I opted for the > sleep/kill-as-insurance combo. Yes that much was clear from the script itself. I didn't mean any of that as a critique of the bcalc script. I just meant it brought to light the point that the coproc pid variable is another thing in the current deallocate-on-terminate behavior, that needs to be copied before it can be used reliably. (With the 'kill' or 'wait' builtins.) Though I do suspect that the most common case with coprocs is that closing the shell's read and write fds to the coproc is enough to cause the coproc to finish promptly - as neither read attempts on its stdin nor write attempts on its stdout can block anymore. I think this is _definitely_ true for the BC coproc in the bcalc example. But it's kind of a distraction to get hung up on that detail, because in the general case there may very well be other scenarios where it would be appropriate to, um, _nudge_ the coproc a bit with the kill command. > (And before you ask why I didn't use `wait -n', I wrote bcalc in 30 > minutes after someone asked me a question about doing floating point > math with awk in a shell script, and it worked.) It's fine! It's just an example, after all :) Carl