title: Killing child processes from parent's signal handler hangs
body: <p>I have a problem in topic of posix processes and I can't get around.</p>
  
  <p>I have a process which forks several children (the process tree can be complex, not only one level). It also keeps track of the active childrens' PID. At some point the parent receives a signal (SIGINT, let's say).</p>
  
  <p>In the signal handler for SIGINT, it iterates over the list of child processes and sends the same signal to them in order to prevent zombies. Now, the problem is that </p>
  
  <ol>
  <li>if the parent does not waitpid() for the child to be stopped, the signal seems to be never dispatched (zombies keep running)</li>
  <li>if the parent waits after every kill() sent to a child, it simply hangs there and the child seems to ignore the signal</li>
  </ol>
  
  <p>Parent and children have the same signal handler, as it's installed before forking.
  Here is a pseudocode.</p>
  
  <pre><code>signal_handler( signal )
      foreach child in children
          kill( child, signal )
          waitpid( child, status )
  
      // Releasing system resources, etc.
      clean_up()
  
      // Restore signal handlers.
      set_signal_handlers_to_default()
  
      // Send back the expected "I exited after XY signal" to the parent by
      // executing the default signal handler again.
      kill( getpid(), signal )
  </code></pre>
  
  <p>With this implementation the execution stops on the waitpid. If I remove the waitpid, the children keep running.</p>
  
  <p>My guess is that unless a signal handler has ended, the signals sent from it are not dispatched to the children. But why aren't they dispatched if I omit wait?</p>
  
  <p>Thanks a lot in advance!</p>