title: How does fork() work?
body: <p>Im really new to forking, what is the pid doing in this code? Can someone please explain what comes out at line X and line Y ?</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #define SIZE 5
  int nums[SIZE] = {0,1,2,3,4};
  int main()
  {
      int i;
      pid_t pid;
      pid = fork();
      if (pid == 0) {
          for (i = 0; i &lt; SIZE; i++) {
              nums[i] *= -i;
              printf("CHILD: %d ",nums[i]); /* LINE X */
          }
      }
      else if (pid &gt; 0) {
          wait(NULL);
          for (i = 0; i &lt; SIZE; i++)
              printf("PARENT: %d ",nums[i]); /* LINE Y */
      }
      return 0;
  }
  </code></pre>