title: Need to know how fork works?
body: <p>I am trying the following C code:</p>
  
  <pre><code>int main()
  {
      printf("text1\n");
      fork();
      printf("text2\n");
      return 0;
  }
  </code></pre>
  
  <p>I was expecting to get the output where i get two "text1" and two "text2", like:</p>
  
  <pre><code>text1
  text1
  text2
  text2
  </code></pre>
  
  <p>But, i am, instead, getting:</p>
  
  <pre><code>text1
  text2
  text2
  </code></pre>
  
  <p>only one "text1"???
  Ok, if child process executes from the fork(), then why do i get two "text1" for following:  </p>
  
  <pre><code>int main()  
  {  
      printf("text1");  
      fork();  
      printf("text2\n");  
      return 0;  
  }  
  </code></pre>
  
  <p>the output now is:  </p>
  
  <pre><code>text1text2  
  text1text2 
  </code></pre>
  
  <p>If the child process starts after the fork, output should be:  </p>
  
  <pre><code>text1  
  text2  
  text2  
  </code></pre>