Waiting on background tasks

Mike Bird mgb-ubuntu at yosemite.net
Mon Apr 10 07:32:19 UTC 2006

On Sun, 2006-04-09 at 22:40, Kenneth P. Turvey wrote:
> Is there a way to start a number of background tasks and then wait for
> them all to complete?  That is I would like something like this:
> longtask arg1 &
> longtask arg2 &
> longtask arg3 &
> waitforalltasks
> #do the next thing

You almost had it:

  longtask arg1 &
  longtask arg2 &
  longtask arg3 &

In some situations, such as in loops or when using pipelines
you'll find that you need parens inside or outside or both:

  (longtask arg1 | foo) &
  while foo; do (longtask arg1 &); done

Try the bare form first and if that doesn't work try adding

--Mike Bird

More information about the ubuntu-users mailing list