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

Re: wait for the next process to finish



Anthony R Fletcher wrote on Tue, Dec 13, 2011 at 11:59:29 -0500:
> > 2011/12/13 Rory Mulvaney <rorymulv@xxxxxxxxx>:
> > > To clarify (I think this is fairly simple), you can supply the process id
> > > as a parameter to 'wait', and though the $! method seems rather clumsy to
> > > retrieve the pid (since you have to retrieve it somehow in the next
> > > command after spawning the background process), it seems to work mostly in
> > > general.
> > >
> > > So you could do:
> > >
> > > sleep 20000 &
> > > sleep 20 &
> > > pid=$!
> > > wait $pid
> > >
> > > That will just wait for the sleep 20 process to complete while the sleep
> > > 20000 process still runs in the background.
> > 
> > Actually, it'll always wait for the last spawned job, not for the
> > first job to finish.
> > 
> > If you spawn them in the reverse order, ie:
> > 
> > sleep 20 &
> > sleep 20000 &
> > pid=$!
> > wait $pid
> > 
> > This will wait for the sleep 20000 process, even if the sleep 20 has
> > finished for long.
> 
> Yes, the need to to wait for any of the processes to end so I can start
> another. Basically a poor man's batch system.

'xargs -P' and 'make -j' were already suggested upthread; is the task
you're trying to parallelize not suitable for those approaches?



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