title: Can this C code create zombie processes?
body: <p>I am wondering if the following code can create zombies:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main(){
      int i=1;
      pid_t p;
      p = fork();
      i++;
      if(p!=0){
          waitpid(p, NULL, 0);
      }
      printf("%d\n",i);
      return 0;
  }
  </code></pre>
  
  <p>So, the parent process calls the waitpid for the child process, which returns immediately if the child has not already exited. So, no zombies can arise so far. But, if the child exits before <pre>return 0;</pre> command this would be a zombie then? I am actually confused about it. Should the waitpid be the last line of code before the program terminates? Any help would be appreciated. Thanks!</p>