zsh-workers
 help / color / mirror / code / Atom feed
From: schaefer@z-code.ncd.com (Barton E. Schaefer)
To: Richard Coleman <coleman@math.gatech.edu>
Cc: zsh-workers@math.gatech.edu
Subject: Re: timing builtins etc.
Date: Thu, 23 Nov 1995 11:11:10 -0800	[thread overview]
Message-ID: <951123111110.ZM13366@zyrcon.z-code.com> (raw)
In-Reply-To: Richard Coleman <coleman@math.gatech.edu> "Re: timing builtins etc." (Nov 23, 11:16am)

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


  reply	other threads:[~1995-11-23 19:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-11-23 10:12 Peter Stephenson
1995-11-23 16:16 ` Richard Coleman
1995-11-23 19:11   ` Barton E. Schaefer [this message]
1995-11-24  7:24 wischnow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=951123111110.ZM13366@zyrcon.z-code.com \
    --to=schaefer@z-code.ncd.com \
    --cc=coleman@math.gatech.edu \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).