title: Waiting for grandchild after child process has died
body: <p>I use the following code to wait for all child processes to finish:</p>
  
  <pre><code>int pid;
  do {
      pid = wait(NULL);
  } while (pid != -1);
  </code></pre>
  
  <p>However, it seems not to work in the event that I have grandchildren running when their parent processes have died.  So for example, say I have process Alpha that forks a child Beta, and Beta forks a child Gamma.  Then Beta dies while Gamma continues to run.  I want to be able to make Alpha wait for Gamma to finish.  The catch is that I am not able to store Gamma's process id - Alpha needs to be able to wait for all children, grandchildren, great-grandchildren, etc. to finish without knowing their individual pids.  Can this be done (if so how)?</p>