title: why does the parent pid return a different value than getpid()?
body: <p>According to the man page </p>
  
  <blockquote>
    <p>getpid()  returns  the  process  ID (PID) of the calling process.</p>
  </blockquote>
  
  <ol>
  <li>In the following code why does the <code>parent pid</code> return a different value than <code>getpid()</code> ? </li>
  <li>Isn't the main process the same as the parent process? </li>
  <li>And why do I get different outputs when run on a different system?</li>
  </ol>
  
  <hr>
  
  <pre><code>#include &lt;sys/types.h&gt;                  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main(int argc, char const *argv[])
  {
  
      printf("getpid = %d \n", (int)getpid());
  
      pid_t pid = fork();
      printf("fork returned %d \n", (int)pid);
  
      switch (pid)
      {
      case -1:
          perror("fork failed");
          break;
  
      case 0:
          printf("I am a child  with pid = %d\n", (int)pid);
          break;
  
      default:
          printf("I am a parent with pid = %d\n", (int)pid);
  
          break;
  
      }
      return 0;
  }
  </code></pre>
  
  <p>output when i run :</p>
  
  <pre><code>getpid = 8208 
  fork returned 8209 
  I am a parent with pid = 8209
  fork returned 0 
  I am a child  with pid = 0
  </code></pre>
  
  <p>output when run on a different pc:</p>
  
  <pre><code>getpid = 2522 
  fork returned 2523 
  I am a parent with pid = 2522
  fork returned 0 
  I am a child  with pid = 2523
  </code></pre>