title: Fork and Zombie process
body: <p>I am trying some simple code on fork.  When I give code like this, it works fine. It will print </p>
  
  <blockquote>
    <p>I am the child</p>
    
    <p>I am the parent</p>
  </blockquote>
  
  <p>and then waits for 30 seconds. I understand this is due to switching between these two process. First child executes then parent and then child...</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  main()
  {
      int pid;
      pid=fork();
      if(pid==0)
      {
          printf("\nI am the child\n");
          sleep(30);
          exit(0);
      }
      if(pid&gt;0)
      {
          printf("\nI am the parent\n");
          wait();
      }
  }
  </code></pre>
  
  <p>But when I gave like (without wait in parent)</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  main()
  {
      int pid;
      pid=fork();
      if(pid==0)
      {
          printf("\nI am the child\n");
          sleep(30);
          exit(0);
      }
      if(pid&gt;0)
      {
          printf("\nI am the parent\n");
  
      }
  }
  </code></pre>
  
  <p>it just prints </p>
  
  <blockquote>
    <p>I am the child</p>
    
    <p>I am the parent</p>
  </blockquote>
  
  <p>and exits ( no waiting for 30 seconds).</p>
  
  <p>So is it because without wait call parent exits and child still executing? But why is it not showing up in terminal (the waiting)?</p>
  
  <p>Whether parent becomes zombie here?</p>