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,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 C49611F44D for ; Mon, 11 Mar 2024 15:13:13 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=luPrfAuT; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0CC43385842C for ; Mon, 11 Mar 2024 15:13:13 +0000 (GMT) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 90D953858418 for ; Mon, 11 Mar 2024 15:12:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90D953858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 90D953858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710169972; cv=none; b=e/6pZfPKhrSsWsgvF36/kWXBx5R15FBW5qj0VKWjvgiUqkXLU19zTF3gNyoc9/GVV5QmBwxoHWJKe8V7Fn1kZhBj2xxHLVn4tAZcsL+tl5mDeV4iVj8GI51B0aLVNmZFUlz3hYA37d8TD5W7kRuNJcCepNCd0ZkviCKKrTI8ZaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710169972; c=relaxed/simple; bh=E0ZM/08h4xVwvhbPxokg9WlFLI1JrdmtUK4F+hXjDts=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=hjRST+xIWsrC9rLYCTjvfXaKWJt6xgUMC7hUbnQuVmJT0E8lx0FrqPWdkT8hvqu3gLYWPUhNnNrtJMShMnhePr59CX23mU9A/1DonSBxGa5gKEVmIXllUNuR0/Lu8yGLGZEj1b7fscqsXITW3dyEWXrkvV31iFrsW+VtAhT0wHg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a450bedffdfso583737966b.3 for ; Mon, 11 Mar 2024 08:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710169967; x=1710774767; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Rxu0MR506EfkVEM3Ja/y0lr7IoFJpBZFgAMCOiEVp+k=; b=luPrfAuTgkoIa/V0DUrWzZszSf/V+Bh2A4OjWxkH9mhpkESQI44ApEpRJUz1NCYQFb fwALlYJTtKveH5FZhUO2OtYrvlMPQGu0GP4R4BvylAxnYLm79Ex70YfvaM0WFLEawhTm km/WWUqMqiuqdhXAP+u6UiCzyhcEbbuZD9rBhwUleBId157VYUbRbKJsW733Dh+gMlMl iAM/wm9tuXB980keF2IUz6i8LCIZFFseWw6vD5jwvIq67tiQ3L3ghyidC64TeSDHJt6E 9zEwE6JlPbhE0Bhh8ov0c3BBnwPIG6FKwk6YaijZ/ItZlhKS5CL/oaAR8VoHdWESNnFz GDtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710169967; x=1710774767; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rxu0MR506EfkVEM3Ja/y0lr7IoFJpBZFgAMCOiEVp+k=; b=be3GOhiUv9+QwYwow40ixI6OHH6ivheseck8Qu9lqOqloPbb69fqKcfeS8I5v+OI6w S6rYboCtnO1vZNn8ilBiU5yvL6j5I2+wsdQxWymXcC3tbnIOamnyP+1NvDslp+GSfgUb eYJm7mf7qca6Yf2xhJi4T9syqxRI6+cAgmjv6Nuh/Nyd8CWhAIIHlWaWA6D1RvmMw2EW SKdZO4RizMMsMtMfv5c3I8mmSM4hxtLQvQdEGUHcAiSUDMCg0U7dQzpQtwZM/0m6xF1G q1doP7PuWy9rM4bws8IDXVIQNaF82bWhgJM3WiTieIvmTkAh/fx+8ID/4ipWKVz3ZexA 1LBQ== X-Gm-Message-State: AOJu0YyL3e9bTq29A1kCth+U588aOwuCDYgbYnBfc43wd+mZ+6zX4Hl5 HPwjepNyylTP/LWFrtdPPCouTbdsJRs2CtNJHHRZa4k1cMTQLrJsR3axBBR53dZ5sNAPld5AQvZ A0ux3rY41SwtN/IaBjObWP7eiOtE= X-Google-Smtp-Source: AGHT+IFmUq9/r5mbGloBdtNiWutzvcVXt1t+cncLQH6f1/nIIRnRr2VWvgw3cE6QkMPZZyDb245sLTpPGQJbZAVlnhE= X-Received: by 2002:a17:907:d049:b0:a46:1fb:1df with SMTP id vb9-20020a170907d04900b00a4601fb01dfmr5403175ejc.42.1710169966979; Mon, 11 Mar 2024 08:12:46 -0700 (PDT) MIME-Version: 1.0 References: <9831afe6-958a-fbd3-9434-05dd0c9b602a@draigBrady.com> <317fe0e2-8cf9-d4ac-ed56-e6ebcc2baa55@cs.wisc.edu> <8c490a55-598a-adf6-67c2-eb2a6099620a@cs.wisc.edu> In-Reply-To: <8c490a55-598a-adf6-67c2-eb2a6099620a@cs.wisc.edu> From: Zachary Santer Date: Mon, 11 Mar 2024 11:12:35 -0400 Message-ID: Subject: Examples of concurrent coproc usage? To: Carl Edquist , bug-bash Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Was "RFE: enable buffering on null-terminated data" On Mon, Mar 11, 2024 at 7:54=E2=80=AFAM Carl Edquist = wrote: > > On Sun, 10 Mar 2024, Zachary Santer wrote: > > > On Sun, Mar 10, 2024 at 4:36=E2=80=AFPM Carl Edquist wrote: > >> > >> Out of curiosity, do you have an example command line for your use cas= e? > > > > My use for 'stdbuf --output=3DL' is to be able to run a command within = a > > bash coprocess. > > Oh, cool, now you're talking! ;) > > > > (Really, a background process communicating with the parent process > > through FIFOs, since Bash prints a warning message if you try to run > > more than one coprocess at a time. Shouldn't make a difference here.) > > (Kind of a side-note ... bash's limited coprocess handling was a long > standing annoyance for me in the past, to the point that I wrote a bash > coprocess management library to handle multiple active coprocess and give > convenient methods for interaction. Perhaps the trickiest bit about > multiple coprocesses open at once (which I suspect is the reason support > was never added to bash) is that you don't want the second and subsequent > coprocesses to inherit the pipe fds of prior open coprocesses. This can > result in deadlock if, for instance, you close your write end to coproc1, > but coproc1 continues to wait for input because coproc2 also has a copy o= f > a write end of the pipe to coproc1's input. So you need to be smart abou= t > subsequent coprocesses first closing all fds associated with other > coprocesses. https://lists.gnu.org/archive/html/help-bash/2021-03/msg00296.html https://lists.gnu.org/archive/html/help-bash/2021-04/msg00136.html You're on the money, though there is a preprocessor directive you can build bash with that will allow it to handle multiple concurrent coprocesses without complaining: MULTIPLE_COPROCS=3D1. Chet Ramey's sticking point was that he hadn't seen coprocesses used enough in the wild to satisfactorily test that his implementation did in fact keep the coproc file descriptors out of subshells. If you've got examples you can direct him to, I'd really appreciate it. > Word to the wise: you might encounter this issue (coproc2 prevents coproc= 1 > from seeing its end-of-input) even though you are rigging this up yoursel= f > with FIFOs rather than bash's coproc builtin.) In my case, it's mostly a non-issue, because I fork the - now three - background processes before exec'ing automatic fds redirecting to/from their FIFO's in the parent process. All the automatic fds get put in an array, and I do close them all at the beginning of a subsequent process substitution.