title: fork and waitpid in C
body: <p>I have this piece of code, maybe I'm missing something:</p>
  
  <pre><code>const int NPROCESSES = 32;   
  pid_t pids[128];
  
  for (int i = 0; i &lt; NPROCESSES;i ++) {
     pids[i] = fork();
     if (!pids[i]) {  
         /*... other code ...*/
         exit(0);
     }
  }
  
  for (int i = 0; i &lt; NPROCESSES; i++)
      waitpid(pids[i], 0, 0);
  </code></pre>
  
  <p>The program should launch 32 processes and wait until all processes are terminated. But sometimes the program get blocked with child zombie processes.
  Where am I wrong?</p>