title: Understanding the processes created by fork()
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt; 
  
  main()
  {
      int i;
  
      for(i=0;i&lt;3;i++)
          if(i%2==0) 
              fork();
          else{
              fork();
              fork();
          }
  } 
  </code></pre>
  
  <p>I understand that it has 16 processes in the end (or at least I think it does), but what I don't understand is which processes are the parent processes and which are the child processes.
  So let's just say that P1 is process 1, P2 is process 2, etc.
  Is P1 the parent of P2, P3, P5, and P9 (I drew this out in a tree but I'm not sure how accurate my tree is), while P2 is the parent of P4, etc.?  Or does P1 become the parent of P2, P3, P4, and something else happens that I don't realize?  I'm just kind of stuck.</p>