title: Why does my forked process's parent pid differ from the parent's own pid?
body: <p>I'm trying to understand how some of <code>unistd.h</code> functions work.
  This is the code I wrote:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(){
    pid_t pid;
    pid=fork();
    switch(pid) {
    case 0: //child
       printf("case 0:\nchild %d\nparent %d\n", getpid(), getppid());
       break;
    default: //parent
       printf("default:\npid(child) %d\nparent %d\n", pid, getpid());
       break;
    }
  }
  </code></pre>
  
  <p>I think that the parent pid obtained by the <code>getppid()</code> in the <code>case 0</code> and the parent pid obtained by the <code>getpid()</code> in the <code>default</code> case should be the same, but this is the output of my little program:</p>
  
  <pre class="lang-none prettyprint-override"><code>default:
  pid(child) 29208
  parent 29207
  
  Process returned 0 (0x0)   execution time : 0.001s
  Press ENTER to continue.
  case 0:
  child 29208
  parent 1017
  </code></pre>
  
  <p>Why are they different? (29207 in a case and 1017 in the other)</p>