title: Why child_1 will print before parent?
body: <p>I have a C code that a parent process will <code>fork()</code> a child process:</p>
  <pre class="lang-c prettyprint-override"><code>int main(){
      pid_t child_1;
      child_1 = fork();
      if (child_1 &gt; 0){
          printf(&quot;Parent: (PID %d)\n&quot;, getpid());
          wait(NULL);
      }
      else if (child_1 == 0){
          printf(&quot;child: %d&quot;, getpid());
      }
  }
  </code></pre>
  <p>And the output is:</p>
  <pre><code>Parent: (PID 1234)
  child: 1235
  </code></pre>
  <p>But if I removed the <code>\n</code> in the <code>printf</code> of parent, the output would become:</p>
  <pre><code>child: 1235Parent: (PID 1234)
  </code></pre>
  <p>I'm not sure why and I've tried on different OS and the output is the same. Thanks in advance.</p>