From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6351 invoked by alias); 20 Apr 2018 10:01:30 -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: 42693 Received: (qmail 6024 invoked by uid 1010); 20 Apr 2018 10:01:30 -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(-6.9/5.0):. Processed in 13.141756 secs); 20 Apr 2018 10:01:30 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS,T_DKIMWL_WL_HIGH,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 20180420100113euoutp01761abb17fb8404d8d34396d603ee16cc~nHKBRlpum2230122301euoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1524218473; bh=ihF1TZveuhmaSQClqiY2r0B7HEByrDVoOlTTwI1fe+w=; h=Date:From:To:Subject:In-reply-to:References:From; b=V9/coXTzwH5q/VdpeGTAN6MGsyuca4pzRGmixR/7MvZpNu2/4hX4vx3ZhKPbPIE7i MyRLiAEqztjOXOLCua4yc8trbh0GdmuvaSFro8/CFrb4D4BO5iJZIyK3dFxMwBLiap X5lzUGAqo6k73E9/AqRsnUoBQTN+vUprhvY8hUC0= X-AuditID: cbfec7f2-1c1ff70000011644-72-5ad9ba68a6b5 Date: Fri, 20 Apr 2018 11:01:10 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Forking earlier for background code Message-id: <20180420110110.599f9cb6@camnpupstephen.cam.scsc.local> In-reply-to: <20180420102839.073d539b@camnpupstephen.cam.scsc.local> 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+NgFnrKIsWRmVeSWpSXmKPExsWy7djP87oZu25GGWz8KGVxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mi50fGUrWMRTsWzrYsYGxl2cXYycHBICJhJrjs1n6WLk4hAS WMEoseXpNmYIp5dJ4vPsZSwwVW93XWaCSCxjlPi4ZSpU1TQmiY71J9kgnDOMEqcvbIYqu8Ao ca/zMmMXIwcHi4CqxMXPMiCj2AQMJaZums0IYosIiEucXXsebIWwgIHE2+kbmUFsXgFniZZX 7WA1nAIuEpduHgIbwy8gJHGh2RbiInuJo3tOMkGUC0r8mHwPbAyzgI7Etm2P2SFseYnNa96C HSohMINN4twOiAYJoJk9vX+gXhOWeHV8CzuELSNxeXI3C0RDM6PE2vv32SASPYwSsxaHQtjW En23LzJCbOCTmLRtOjPIcRICvBIdbUIQJR4S1y59hprpKLFqbxsrJExusUscbuxhmsAoPwvJ 4bOQHD4LyeELGJlXMYqnlhbnpqcWG+allusVJ+YWl+al6yXn525iBEb+6X/HP+1g/Hop6RCj AAejEg/vh3U3ooRYE8uKK3MPMUpwMCuJ8CaY3YwS4k1JrKxKLcqPLyrNSS0+xCjNwaIkzhun URclJJCeWJKanZpakFoEk2Xi4JRqYMyx4Zj60qixadXeu3ox23znLd2256r/8x3snU/kq5T5 dfv+Hu+5uV31h9wWrwkfS/+wRtleOh8iyqvx1jpkZxOrjdHjNSJMfREl2xas2LP157KnVVey Jy/T2d+0/2Hbdn3BKlkVDsO1vl6757SKWE0QvD9NetLNqcvuPvbinvfWIWN2SPuHhweVWIoz Eg21mIuKEwHS8kpJ+AIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t/xq7rpu25GGXRuM7c42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGRc6vrIVLOKpWLZ1MWMD4y7OLkZODgkBE4m3uy4zdTFycQgJ LGGUmD9xBQuEM4NJ4veMqewQzjlGiU9nFrNCOBcYJX513QNyODhYBFQlLn6WARnFJmAoMXXT bEYQW0RAXOLs2vMsILawgIHE2+kbmUFsXgFniZZX7WA1nAIuEpduHmKEmHmLXeLLk1VsIDP5 BYQkLjTbQpxnL3F0z0kmiF5BiR+T74HNZBbQkti8rYkVwpaX2LzmLdh8IQF1iRt3d7NPYBSa haRlFpKWWUhaFjAyr2IUSS0tzk3PLTbSK07MLS7NS9dLzs/dxAgM2m3Hfm7Zwdj1LvgQowAH oxIP74d1N6KEWBPLiitzDzFKcDArifAmmN2MEuJNSaysSi3Kjy8qzUktPsQozcGiJM573qAy SkggPbEkNTs1tSC1CCbLxMEp1cBopPbpi2Rm0QG1ktW+tn0NbvElv89Un8qOmshvnMGcxldg arT06CduNiF+zqnqipO/2Ab5OXOkSMXaVsw5/3zuqnyVnryfUufUBMMu5nO/tOO+1HHkj2vK M7u3ByV/7O15K1s+NztNY27u61zryY6CVksUGyM4TiVtfvmvzHh1/4y52z6zKyuxFGckGmox FxUnAgD7vkxrVgIAAA== X-CMS-MailID: 20180420100111eucas1p2564a9669ab39b0055e46a422f92ab3cc X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180324221021epcas1p184507a6328dbd505b97db69c1f9d8194 X-RootMTR: 20180324221021epcas1p184507a6328dbd505b97db69c1f9d8194 References: <180323221959.ZM27569@torch.brasslantern.com> <20180324080514.txxyrb3qiztu4pqt@gmail.com> <180324150945.ZM32251@torch.brasslantern.com> <20180410124545.13fccd5d@camnpupstephen.cam.scsc.local> <20180410145926.64c4f671@camnpupstephen.cam.scsc.local> <180411151025.ZM19332@torch.brasslantern.com> <20180412172342.52df6b10@camnpupstephen.cam.scsc.local> <20180415162326.GA12549@chaz.gmail.com> <20180415185804.GB12549@chaz.gmail.com> <180416223910.ZM32002@torch.brasslantern.com> <20180417101947.5fd347df@camnpupstephen.cam.scsc.local> <180417090926.ZM2456@torch.brasslantern.com> <20180417173558.769503bd@camnpupstephen.cam.scsc.local> <180417105243.ZM2929@torch.brasslantern.com> <20180419104039.7b86ed2b@camnpupstephen.cam.scsc.local> <20180420102839.073d539b@camnpupstephen.cam.scsc.local> (Sorry about multiple messages, but I'm sure you're fascinated...) On Fri, 20 Apr 2018 10:28:39 +0100 Peter Stephenson wrote: > It may well be possible to expand the logic to track down other cases > where we know we can know we're going to need to fork, so can do so > early to get fewer side effects (and slightly optimise the main > shell). >... > So I think if "last1" is zero and "output" is non-zero we might be > able to fork early, perhaps? If you want to play along at home with step 1 here, try the following. As far as I can see, we don't need to take special account of "exec" here. For the pipeline to work we always need to fork even if the command has the "exec" keyword in front (same true of "&", in fact). diff --git a/Src/exec.c b/Src/exec.c index 1b622d5..768e3ef 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3146,10 +3146,11 @@ execcmd_exec(Estate state, Execcmd_params eparams, esprefork = (magic_assign || (isset(MAGICEQUALSUBST) && type != WC_TYPESET)) ? PREFORK_TYPESET : 0; - if (how & Z_ASYNC) { + if ((how & Z_ASYNC) || (output && !last1)) { /* - * If running in the background, we don't need any of - * the rest of this functino to affect the state in the + * If running in the background, or not the last command in a + * pipeline and not already forked, we don't need any of + * the rest of this function to affect the state in the * main shell, so fork immediately. * * In other cases we may need to process the command line pws