From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28135 invoked by alias); 10 Apr 2018 09:53:55 -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: 42615 Received: (qmail 5919 invoked by uid 1010); 10 Apr 2018 09:53:55 -0000 X-Qmail-Scanner-Diagnostics: from mailout1.w1.samsung.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(210.118.77.11):SA:0(-1.9/5.0):. Processed in 15.191573 secs); 10 Apr 2018 09:53:55 -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,SPF_HELO_PASS, SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180410095334euoutp01b3705faa42a0d8928c256696b4940378~kCmevDMwi1836218362euoutp01M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1523354014; bh=tI7JoGNxdcF5LGQ0/LdwNOBNmH1nmvX08E2bgqClxCU=; h=Date:From:To:Subject:In-reply-to:References:From; b=cisfCx04NgVh5iJSvSR2OYHmoLyezHgZwxe88ajwJlNY8YARn0qvTqtr0E5n9IpYL EHmBGInaNXQc5jtiZUlSAfNHdl5qzMf3zsl9XIVSNNh8r5I1V61gvSu2ldQ7TKYK+c JhQ2/8n1mvV99TuPrV6IMOHUMdvSwya/o0woJN4c= X-AuditID: cbfec7f4-713ff700000043e4-aa-5acc899d6b20 Date: Tue, 10 Apr 2018 10:53:30 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups Message-id: <20180410105330.704853ae@camnpupstephen.cam.scsc.local> In-reply-to: <180323163614.ZM10192@torch.brasslantern.com> Organization: SCSC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMIsWRmVeSWpSXmKPExsWy7djPc7pzO89EGRz+xmtxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mo7+/cdYcEqy4ta9SUwNjFOFuxg5OSQETCT6P/UzdjFycQgJ rGCUuHliHhtIQkigl0mia6FyFyMHWNHuXSwQNcsYJf5c62CCcKYxSTQfX8YK4ZxhlGj6/hjK ucAose7rF3aQUSwCqhLvz68Fs9kEDCWmbprNCGKLCGhJ7Dh5kgnEFhZIkDi7ZweYzSvgLPF7 636wek4BK4l5y58wgZzBLyAkcaHZFuJse4mje05ClQtK/Jh8jwXEZhbQkdi27TE7hC0vsXnN W2aI+ilsEnd/G0HYLhJHf3+CigtLvDq+hR3ClpHo7DgI9pmEQDOjxNr799kgEj2MErMWh0LY 1hJ9ty8yQizgk5i0bTozJIh4JTrahCBKPCSeTrjEAmE7Ssz7vosZEibbGCUmnWpln8AoPwvJ 3bOQ3D0Lyd0LGJlXMYqnlhbnpqcWG+WllusVJ+YWl+al6yXn525iBEb96X/Hv+xg3PUn6RCj AAejEg/vhIOno4RYE8uKK3MPMUpwMCuJ8B5cDBTiTUmsrEotyo8vKs1JLT7EKM3BoiTOG6dR FyUkkJ5YkpqdmlqQWgSTZeLglGpgVLgbsJLnrInGIk+dL78XPzfUPfbIWPB5UkXuzZKT3s+T 2JgcFFdy7wvMTjrU9SfqmPVPx/+3vvLOu/ghYP3lLVJzeYK+SE+ZEVmzXagv7NQWiej+tq7a mTNKz1cn8PN8i/y6t03K98i5Bb46Gj7fbr15v8Zx7Q7LtvNPixhTPrC3rZFgmRBorsRSnJFo qMVcVJwIAM0MQBn2AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrILMWRmVeSWpSXmKPExsVy+t/xa7pzOs9EGfx/p2lxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mo7+/cdYcEqy4ta9SUwNjFOFuxg5OCQETCR272LpYuTiEBJY wiixs2c7UxcjJ5Azg0mi/SgfROIco8TSPROgEhcYJd4/MgGxWQRUJd6fX8sOYrMJGEpM3TSb EcQWEdCS2HHyJFi9sECCxKInE8DivALOEr+37ger5xSwkpi3/AkTxIJtjBKTF5xkBbmIX0BI 4kKzLUiNhIC9xNE9EHN4BQQlfky+xwJiMwPN37ytiRXClpfYvOYtM8Rt6hI37u5mn8AoNAtJ yywkLbOQtCxgZF7FKJJaWpybnltsqFecmFtcmpeul5yfu4kRGLDbjv3cvIPx0sbgQ4wCHIxK PLwTDp6OEmJNLCuuzD3EKMHBrCTCe3AxUIg3JbGyKrUoP76oNCe1+BCjNAeLkjjveYPKKCGB 9MSS1OzU1ILUIpgsEwenVAPj9PkhpkkCDofDTSrrl23Q+H9c0PCgyJGauviqzffaxU8xfGOd tdfCQ9faLVRFweyB0MWwTbxGbIeXXA2ffGWhkNJi+UipD+4hTdX+lZsuqm60uLrg8tOkNys4 4zLXT7KaLVbw+p/o90oX3qMLhU7Lny/b42W7fLf3vLrrn0uiXuzIOZ45k1lYiaU4I9FQi7mo OBEALCQS7VQCAAA= X-CMS-MailID: 20180410095332eucas1p215ff723c05d45ca5967d11a5f19ceb84 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180323235316epcas2p3ee393671af9e1b11430efd35e32678c3 X-RootMTR: 20180323235316epcas2p3ee393671af9e1b11430efd35e32678c3 References: <20180323161612.GB4857@chaz.gmail.com> <180323163614.ZM10192@torch.brasslantern.com> On Fri, 23 Mar 2018 16:36:14 -0700 Bart Schaefer wrote: > 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). >... > 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. >... > 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. The following patch gives me the same with and without the $(:). Changing gleader ASAP seems the only sane thing to do --- else we end up in a maze of forks and none of the subshells know what's going on. But I'm a bit worried that we're going to end up with something following the original leader and something not? If that did happen, does it mean the pgrp is still valid, and if so can we test that without actually changing it? Or does it mean there's no zsh-specific problem because those earlier processes are pgrp orphans in any case? As the setpgrp() happens in subprocess I don't think there's any future in recording what processes have set the process group already. Surely this must be a "well-known problem" with a "well-known" solution? I'm not convinced Joey's case is actually (directly) related to this (or rather, to anything fixed by this or Bart's change --- it's obviously somewhere in the same area). % echo | ps -j $(:) | cat | cat | cat PID PGID SID TTY TIME CMD 18367 18367 18367 pts/4 00:00:07 zsh 20179 20179 18367 pts/4 00:00:02 zsh 20199 20199 18367 pts/4 00:00:00 ps 20200 20199 18367 pts/4 00:00:00 cat 20201 20199 18367 pts/4 00:00:00 cat 20202 20199 18367 pts/4 00:00:00 cat % echo | ps -j | cat | cat | cat PID PGID SID TTY TIME CMD 18367 18367 18367 pts/4 00:00:07 zsh 20179 20179 18367 pts/4 00:00:02 zsh 20204 20203 18367 pts/4 00:00:00 ps 20205 20203 18367 pts/4 00:00:00 cat 20206 20203 18367 pts/4 00:00:00 cat 20207 20203 18367 pts/4 00:00:00 cat diff --git a/Src/signals.c b/Src/signals.c index 94f379e..5917683 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -537,6 +537,18 @@ wait_for_processes(void) #else update_process(pn, status); #endif + if (pn->pid == jn->gleader) { + Process pnn = pn->next; + while (pnn) { + if (pnn->status == SP_RUNNING) { + jn->gleader = pnn->pid; + break; + } + pnn = pnn->next; + } + if (pn->pid == jn->gleader) + jn->gleader = 0; + } } update_job(jn); } else if (findproc(pid, &jn, &pn, 1)) { pws