title: SIGCHLD handler in c - unwanted wait
body: <p>I've the following problem with the SIGCHLD handler function.</p>
  
  <p>The handler code is pretty simple:</p>
  
  <pre><code>void sigchld_handler(int signum)
  {
      pid_t ended;    
      signal(SIGCHLD, sigchld_handler);
      ended = wait(NULL);
      // do some stuff with the PID of the finished child process
  }
  </code></pre>
  
  <p>This works well when I fork only one child. If I have 2 children (or more) and one of them has finished running, the sigchld_handler() starts and when it gets to the "ended = wait(NULL)" line, the program waits until the other child I have finishes.</p>
  
  <p>Is there a way to get the PID of the child that just ended in a different way and avoid this wait?</p>