title: How can the multi-core cpu run the program interleaved?
body: <p>The output of the program are not obviously contents from the <code>printf()</code>s in teh code. Instead it looks like characters in irregular sequence. I know the reason is because the parent process and child process are running
  at the same time, but in this program I only see <code>pid=fork()</code>, which I think means pid is only the id of child process.<br />
  So why can the parent process print?<br />
  How do the two processes run together?</p>
  <pre><code>// fork.c: create a new process
  
  #include &quot;kernel/types.h&quot;
  #include &quot;user/user.h&quot;
  
  int
  main()
  {
    int pid;
  
    pid = fork();
  
    printf(&quot;fork() returned %d\n&quot;, pid);
  
    if(pid == 0){
      printf(&quot;child\n&quot;);
    } else {
      printf(&quot;parent\n&quot;);
    }
    
    exit(0);
  }
  </code></pre>
  <p>output:</p>
  <pre><code>ffoorrkk(())  rreettuurrnende d 0
      
  1c9h
  
  ilpda
  
  rent
  </code></pre>