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

Re: wait for the next process to finish



Hi,

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.

Best regards,

-- 
Jérémie



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