From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from math.gatech.edu (euclid.skiles.gatech.edu [130.207.146.50]) by werple.net.au (8.7/8.7.1) with SMTP id GAA19859 for ; Fri, 24 Nov 1995 06:29:52 +1100 (EST) Received: by math.gatech.edu (5.x/SMI-SVR4) id AA00402; Thu, 23 Nov 1995 14:08:09 -0500 Resent-Date: Thu, 23 Nov 1995 11:11:10 -0800 Old-Return-Path: From: schaefer@z-code.ncd.com (Barton E. Schaefer) Message-Id: <951123111110.ZM13366@zyrcon.z-code.com> Date: Thu, 23 Nov 1995 11:11:10 -0800 In-Reply-To: Richard Coleman "Re: timing builtins etc." (Nov 23, 11:16am) References: <199511231616.LAA02869@redwood.skiles.gatech.edu> Reply-To: schaefer@z-code.ncd.com X-Face: czU|*h"p8AX?4.I.yU.^s%TIMx|"-s,*'|#H^|e,QjE&!jL%<]:-.U/;khS%3a2BC5_d#)( mz=$$G0u9P&*N8cA~b[URf;lgKRif@#qEf[ltie#Gg0%6$b`e`k.Cgw:\qJx\\a7c(K7^3;gXW:e1@ J Subject: Re: timing builtins etc. Cc: zsh-workers@math.gatech.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-Id: <"AG6l5.0.C6.PQCjm"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/639 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Nov 23, 11:16am, Richard Coleman wrote: } Subject: Re: timing builtins etc. } } In execpline2, there is the comment } } /* if we are doing "foo | bar" where foo is a current * } * shell command, do foo in a subshell and do the * } * rest of the pipeline in the current shell. */ } } Does anyone know why this special case was added? It's not really a special case for pipelines; pipelines always fork off the left side and then process the rest of the pipeline in the current shell. It's a special case for builtins and shell functions only because they are not normally forked off at all. You have to fork one side of the pipeline or the other in order to set up the pipe between the processes. You could do the builtin in the current shell and fork a subshell for the right side, but it's more logical to fork the left side first because it's the producer on which the right side consumer depends. Besides, a builtin or shell function might appear somewhere in the right side, too. } Because of this, if you try to do something like } } jobs | wc -l } } it doesn't do what people expect. Since `jobs' runs in a subshell, } there are no jobs to report, so the above line always returns 0. Csh has this restriction, too. You're surely aware that the reason that there are no jobs to report has nothing to do with the actual process tree. Any subshell could print out the jobs list as easily as the parent could. It's just that the jobs list gets thrown away when a subshell is entered, so there's nothing to print. Zsh does the left side in a subshell because executing in a subshell sets up all the correct entry and exit conditions (true fork rather than vfork, etc.), so that e.g. the child won't mess up the "real" shell's tty and so forth. Ideally, the notion of being a forked copy of the current shell would be separate from the notion of being a lexical subshell, so that entry and exit conditions would be separate from clearing the job table and other subshell requirements. This must be what bash is doing. } I checked bash and it returns the correct answer. What does bash do if you put "fg" on the left side of a pipe? Note that "jobs" and "fg" have traditionally been the same builtin at the C code level in zsh, and for "fg" the process tree really does make a difference. And what does bash do with ( jobs ) | wc -l ?? -- Bart Schaefer Vice President, Technology, Z-Code Software schaefer@z-code.com Division of NCD Software Corporation http://www.well.com/www/barts