Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

23
  • 12
    Weel, since you are going to wait for all the processes it doesn't matter if e.g. you are waiting on the first one while the second has already finished (the 2nd will be picked at the next iteration anyway). It's the same approach that you'd use in C with wait(2). Commented Dec 10, 2008 at 14:41
  • 8
    Ah, I see - different interpretation :) I read the question as meaning "return exit code 1 immediately when any of subprocesses exit". Commented Dec 10, 2008 at 14:51
  • 77
    PID may be reused indeed, but you cannot wait for a process that is not a child of the current process (wait fails in that case). Commented Dec 10, 2008 at 15:27
  • 13
    You can also use %n to refer to the n:th backgrounded job, and %% to refer to the most recent one. Commented Aug 12, 2010 at 11:13
  • 30
    @Nils_M: You're right, I'm sorry. So it would be something like: for i in $n_procs; do ./procs[${i}] & ; pids[${i}]=$!; done; for pid in ${pids[*]}; do wait $pid; done;, right? Commented May 27, 2014 at 15:15