title: Fork command in shell to print process ids
body: <p>I am trying to print the <code>pid</code> of the processes after running the <code>fork()</code> command. Here is my code-</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(void)
  {
      int pid;
      pid=fork();
      if(pid==0)
          printf("I am the child.My pid is %d .My parents pid is %d \n",getpid(),getppid());
      else
          printf("I am the parent.My pid is %d. My childs pid is %d \n",getpid(),pid);
      return 0;
  }
  </code></pre>
  
  <p>This is the answer I am getting-</p>
  
  <pre><code>I am the parent.My pid is 2420. My childs pid is 3601 
  I am the child.My pid is 3601 .My parents pid is 1910 
  </code></pre>
  
  <p>Why is the parents id in 2nd line not <code>2420</code>.Why am I getting <code>1910</code> How can I get this value?</p>