title: Parent Process not Waiting for Children - C
body: <p>I am writing a program that is intended to pin the CPU usage, I am using it as a tool to measure performance. The program is fairly simple in that it spawns 5 child processes from the parent. Below is a snipped of my code</p>
  
  <pre><code>int main(int argc, char **argv) {
    pid_t pid = 0; 
    int i;
  
    for(i = 0; i &lt; 5; i++)
      //create 5 additional processes
      if((pid = fork()) == 0) {
          //do CPU intensive task
        break;
      }
  
    //fork error 
    if(pid == -1) {
      perror("&lt;fork failed&gt;\n");
      return EXIT_FAILURE;
    }
  
    //if parent
    if(pid != 0)
      //wait for children to finish
      wait(NULL);
  
    return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>However the parent process exits right away, despite the wait(NULL) function. Any ideas as to why this is happening and how it could be fixed would be greatly appreciated.</p>