title: C fork dealing with global variable
body: <p>I'm not understanding the output of this program:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int i = 0;
  
  int main()
  {
      while(i&lt;3)
      {
          fork();
  
          printf("%d\n",i);
          ++i;
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>0
  1
  2
  2
  1
  2
  0
  1
  2
  2
  2
  1
  2
  2
  </code></pre>
  
  <p>Can please someone tell me how I should tackle this issue in order to fully understand why I'm getting this output?</p>