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

Re: wait for the next process to finish



On Mon, 12 Dec 2011 10:46:01 -0500
Anthony R Fletcher <arif@xxxxxxxxxxxx> wrote:
> I just realised that the 'wait' command will either wait for specified
> jobs or all jobs and nothing in between. The manual says "If job is not
> given then all currently active child processes are waited for.".
> 
> So 
> 	sleep 30 &
> 	sleep 10 &
> 	sleep 30 &
> 	sleep 30 &
> 	wait
> waits for all the sleeps to finish.
> 
> How can I wait for just the next job to finish?

Certainly the shell internals don't help you here.  There's code to look
at a specific job, decide if it's still going, and exit when it isn't,
which is behind the wait builtin with an argument.  There's nothing to
loop over all jobs, decide what's still going, wait for something to
happen, then work out what it was and hence if it can stop waiting.

The reason waiting for all jobs works is simply that it waits for jobs
in order; if an earlier job exits first it gets handled by the signal
handler, but the shell foreground doesn't notice until the job it's
actually waiting for exits, then it carries on down the list and picks
up anything that's already exited.

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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