title: How do multiple fork statements work?
body: <p>If I run the following code : </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main()
  {
      pid_t pid, pid1;
      fflush(stdout);
      pid = fork();
      fflush(stdout); 
      pid1 = fork();
      if(pid==0)
      {
           printf("%d is the first child\n", getpid() );
      }
      else if(pid&gt;0)
      {
           printf("%d is the first parent\n", pid);
          wait();
      }
      if(pid1==0)
      {
           printf("%d is the second child\n", getpid() );
      }
      else if(pid1&gt;0)
      {
           printf("%d is the second child\n", pid1);
          wait();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I get the output :</p>
  
  <pre><code>2896 is the first parent
  2896 is the first child
  2898 is the first child
  2898 is the second child
  2898 is the second child
  2896 is the first parent
  2897 is the second child
  2897 is the second child
  </code></pre>
  
  <p>I cannot understand the output. Why are the same strings being printed multiple times ?</p>