saving the returnin value of fork in a variable in C : <p>I am a bit confused about the value which the function fork returns. I understand that value <code>0</code> is for <code>child</code> process and value <code>&gt;0</code> is for <code>parent</code> process. 
I have the code below</p>

<pre><code>int main()   
{    
   int pid;
   pid = fork();
   if(pid == 0)
       //DO SOMETHING
   else
       //DO SOMETHING ELSE 
   return 0;
}
</code></pre>

<p>The valiable <code>pid</code> after fork is different for each process ?
I can't understand how it switches value. And I have a second part with code </p>

<pre><code>int main()
{
    int pid;
    if (pid == 0)
    {
          return 5;
    }
    printf("parent = %d waits for child = %d ", getpid(), pid);
    waitpid(pid, NULL, 0);
    printf("child terminates!")
    return 0;
}
</code></pre>

<p>in which I can't understand why pid on line with first <code>printf</code> has the value of child. It shouldn't be the <code>id</code> of parent ?</p>
