Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: why does "jobs | wc" not work?



Dominik Vogt wrote:
> > In zsh
> > 
> > jobs | anything
> > 
> > causes the shell to fork for the left hand side of the pipeline.
> 
> Um, why must builtin commands run in a subshell?  I would have
> naively thought commands like "echo something | ..." would just
> run in the current shell.  Spawning a subshell sounds a bit
> inefficient.

That's how all pipes work in all shells and scripting languages in all
variants of UNIX:  one process feeds its output to another process, so
one side of the pipe has to be forked as a separate process.  The only
question is which bits are forked off.

The only obvious alternative is the horrible method which used to be
used in MSDOS: fake separate processes by switching between the two
tasks; but we are certainly never going to have a task manager in the
shell when we have a proper multiprocessor operating system to do the
job more efficiently.

> > In 4.1, we use the obvious workaround:  remember that we're in a subshell
> > of an interactive shell and keep a fossilized list of the jobs.
> 
> Obvious, maybe, but it still sounds wrong in my ears.

Just in case my explanation above hasn't made this remark obvious:
wrong in what way?  It's either that or no output at all.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************




Messages sorted by: Reverse Date, Date, Thread, Author