title: Why is sleep in a child process blocking my program?
body: <p>So I have this simple program that sleeps for 4 second if the value returned by fork is '0' meaning that the child process is executing, I've tried using sleep in child process but the program is blocked, and flushing standard output isn't working...
  code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char const *argv[]) {
    pid_t value = fork();
  
    if (value == 0) {
      sleep(4);
    }
    
    printf(&quot;Value returned by fork: %d\n&quot;, value);
    printf(&quot;I'm the process N°%d\n&quot;, getpid());
    
    return 0;
  }
  </code></pre>
  <p>I'm running on Ubuntu 20.04.3 LTS.</p>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code>Value returned by fork: 12618
  I'm the process N°12617\
  farouk@farouk-HP-Pavilion-Desktop-TP01-1xxx:~/sysexp$  Value returned by fork: 0
  I'm the process N°12618
  </code></pre>
  <p><a href="https://i.stack.imgur.com/T2LxP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T2LxP.png" alt="enter image description here" /></a></p>