From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26795 invoked by alias); 23 Mar 2018 23:36:25 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42514 Received: (qmail 27443 invoked by uid 1010); 23 Mar 2018 23:36:25 -0000 X-Qmail-Scanner-Diagnostics: from mail-pl0-f47.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.160.47):SA:0(-1.9/5.0):. Processed in 2.768989 secs); 23 Mar 2018 23:36:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=3+/ZPUHDFQxgxVvwqAPO2ATAEHn3k6pjf0UQOe65hjY=; b=XmjnEZM32wr5ArD7TUDnoel9DQguHdRTDwe2u61bakSydF+adquKJhNyTxZxtnEfAE uorJQWNfIJy4wmR4bYlgwZCL0nsOPe8g5uQqgR2ihiSRgl4svPqYE9IxeHWGTt21iGJk 3lIofJ23/1ZAcDzjFdkqEc224rHQ6j83BsZas6FN8KDMt9b1A0/b0pKzzafmibX8bcMK lYPRLuXxGVsnwS7h5/eHalL8I78rnBKN07W1AGfwQSfrvdx3S8QRd8TOTS77umgQeI3w 2fR0J/wHJTatrlju/PCyB5IpXgDSPQo7sWC1soyWh42UeVnUmEVO2Ds4he+m29Jyl5l4 X7vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=3+/ZPUHDFQxgxVvwqAPO2ATAEHn3k6pjf0UQOe65hjY=; b=OL4xYW3K6Tb/wRjNfVg0KVchxBWbZANeyHHwcOTatZ29a5JmxragmbTqDVnaE9CpRF GLVnut+5wR/ASDeOHjJswzsg89LPC3bL3DoPtV3rfz4ZBDqbthngAmgK3bF4BdaNv2H3 sfw86SRuAkeRnXg7M56ZaEgL9l9WVu1mT3RQZBhIr+bOfdvHTJ25zZynAXHtofaQq8lj n0365XtuTO9NLpMXvubFdGHi6p9BFJs/SMG2Wmw130xKOlPDSP8fueRCeXrxBisi8wEQ Jwq+N2ja9BAv4YoxiUmWrUb3nJBvuQDVTQEVMOy+P39xX53Y+1/6Kz/5ZrRfbTDkNj/1 9y3A== X-Gm-Message-State: AElRT7Gy/C5uUY8KZ7xYsQFdspp7JxmQBq4YWyzjKC7d3jlDkbCzH0Df CKxe6cKIAQojfUsUPveimDF3fILH X-Google-Smtp-Source: AG47ELsw8y5Q9oWr+KlqHBKZlyfwgNrZOhVRqb8uurcOd75kkvXOgUUaMkm7IItBdmg5x6p6T6+S/Q== X-Received: by 2002:a17:902:3181:: with SMTP id x1-v6mr13566128plb.269.1521848178685; Fri, 23 Mar 2018 16:36:18 -0700 (PDT) From: Bart Schaefer Message-Id: <180323163614.ZM10192@torch.brasslantern.com> Date: Fri, 23 Mar 2018 16:36:14 -0700 In-Reply-To: <20180323161612.GB4857@chaz.gmail.com> Comments: In reply to Stephane Chazelas ""echo | ps -j $(:) | cat | cat | cat" runs components in different process groups" (Mar 23, 4:16pm) References: <20180323161612.GB4857@chaz.gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Mar 23, 4:16pm, Stephane Chazelas wrote: } } $ echo | ps -j $(:) | cat | cat | cat } PID PGID SID TTY TIME CMD } 4858 4858 4858 pts/4 00:00:02 zsh } 23813 23813 4858 pts/4 00:00:00 zsh } 23895 23895 4858 pts/4 00:00:00 ps } 23896 23896 4858 pts/4 00:00:00 cat } 23897 23897 4858 pts/4 00:00:00 cat } 23898 23898 4858 pts/4 00:00:00 cat } } See how they all run in different process groups (they should } all be in the same one, same job). Hmm: % strace -ff -p 9850 -esetpgid Process 9850 attached - interrupt to quit Process 10029 attached [pid 10029] setpgid(0, 10029) = 0 Process 10030 attached Process 10029 detached [pid 9850] --- SIGCHLD (Child exited) @ 0 (0) --- Process 10030 detached --- SIGCHLD (Child exited) @ 0 (0) --- Process 10031 attached [pid 10031] setpgid(0, 10029) = -1 EPERM (Operation not permitted) [pid 10031] setpgid(0, 10031) = 0 Process 10032 attached [pid 10032] setpgid(0, 10029) = -1 EPERM (Operation not permitted) [pid 10032] setpgid(0, 10032) = 0 Process 10031 detached [pid 9850] --- SIGCHLD (Child exited) @ 0 (0) --- Process 10032 detached --- SIGCHLD (Child exited) @ 0 (0) --- Here 10029 is "echo" (forked to the left, as zsh does) and 10030 is the process substitution $(:). 10031 is "ps" and 10032 is "cat". Zsh wants to use "echo" as the group leader because it was the first to fork, but because $(:) delayed the execution of "ps" the "echo" process has already exited and cannot be made group leader. As the fallback the other processes each get made into its own process group. So it's a race condition, adding the process substitution just happens to expose it. I'm not sure whether it would work to postpone reaping the would-be group leader when that first SIGCHILD is received; can a zombie lead a group? Otherwise we'd have to notice that the group leader is gone and change to the second forked process, and so on, until we found a leader that would stick for the remainder of the forks.