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.

10
  • 156
    jobs -p is giving PIDs of subprocesses that are in execution state. It will skip a process if the process finishes before jobs -p is called. So if any of subprocess ends before jobs -p, that process's exit status will be lost. Commented Feb 8, 2009 at 15:06
  • 21
    Wow, this answer is way better than the top rated one. :/ Commented Mar 29, 2012 at 0:03
  • 4
    @e40 and the answer below is probably even better. And even better would probably be to run each command with '(cmd; echo "$?" >> "$tmpfile"), use this wait, and then read file for the fails. Also annotate-output. … or just use this script when you don't care that much. Commented Mar 29, 2012 at 10:18
  • 4
    @tkokoszka to be accurate jobs -p is not giving PIDs of subprocesses, but instead GPIDs. The waiting logic seems to work anyway, it always waits on the group if such group exists and pid if not, but it's good to be aware.. especially if one were to build upon this and incorporate something like sending messages to the subprocess in which case the syntax is different depending on whether you have PIDs or GPIDs.. i.e. kill -- -$GPID vs kill $PID Commented Mar 1, 2018 at 13:40
  • 1
    sounds so simple as in this answer, right? Wrong! If you put those sleeper things on a for or while loop, it becomes child shell. and the jobs or wait doesn't consider child shell's background jobs. so, that's why we should use the accepted answer, even though it looks complex. Commented Aug 4, 2020 at 5:59