title: (fork / waitpid) Wait for a list of child processes but interrupt the wait every time a child finishes
body: <p>I'm using <code>fork</code> to spawn a number of child processes that run several tasks in parallel. In my case it is not sufficient to simply wait on all child processes in a loop, because if the first process in my list is the last to finish then my <code>waitpid</code> call would block until that process has finished.</p>
  
  <p>I want my <code>waitpid</code> call to wake up every time a process has finished. The reason is that I immediately want to inspect the finished child process's exit code to determine if the process was successful so I can cancel any child processes still running. In my case, there is no point in letting them continue (potentially for hours!) if any child process returns a non-zero exit code because that would indicate an error, and even a single error would make the whole undertaking pointless.</p>
  
  <p>(EDIT: I know that that's not how <code>waitpid</code> actually works, but I'm looking for something like that.)</p>
  
  <p>Now, I <em>could</em> do this by using a loop to call <code>waitpid</code> with the <code>WNOHANG</code> flag and then keep checking my child processes with sleep intervals between individual <code>waitpid</code> calls, but this solution seems like a hack. Does anyone have a more elegant solution?</p>