title: fork() child and parent processes
body: <p>I am trying to create a program that uses fork() to create a new process. The sample output should look like so:</p>
  
  <p>This is the child process. My pid is 733 and my parent's id is 772.<br>
  This is the parent process. My pid is 772 and my child's id is 773.</p>
  
  <p>This is how I coded my program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      printf("This is the child process. My pid is %d and my parent's id is %d.\n", getpid(), fork());
  
      return 0;
  }
  </code></pre>
  
  <p>This results in the output:</p>
  
  <p>This is the child process. My pid is 22163 and my parent's id is 0.<br>
  This is the child process. My pid is 22162 and my parent's id is 22163.</p>
  
  <p>Why is it printing the statement twice and how can I get it to properly show the parent's id after the child id displays in the first sentence?</p>
  
  <p>EDIT:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
  int pid = fork();
  
  if (pid == 0) {
      printf("This is the child process. My pid is %d and my parent's id is %d.\n", getpid(), getppid());
  }
  else {
      printf("This is the parent process. My pid is %d and my parent's id is %d.\n", getpid(), pid);
  }
  
  return 0;
  }
  </code></pre>