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

Re: wait for the next process to finish



> 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.

			Anthony.

-- 
Anthony R Fletcher        
  Room 2033, Building 12A,        http://dcb.cit.nih.gov/~arif
  National Institutes of Health,  arif@xxxxxxxxxxxx
  12A South Drive, Bethesda,      Phone: (+1) 301 402 1741.
  MD 20892-5624, USA.



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