title: Does a read() in parent process wait for a child write() in a pipe?
body: <p>I want to make a pipe between a child-writer and a parent-reader in C.
  I thought that my parent process would have to wait for its child to write in the buffer before being able to read it, but then I wanted to check it so I wrote the following piece of code:</p>
  
  <pre><code>pipe(fd);
  // ... checks for pipe
  pid_t pid = fork();
  // ... checks for fork
  if (pid == 0) {
      close(fd[0]);
      // Long sleep hoping parent will terminate before the write()
      sleep(10);
      write(fd[1], "hello", strlen("hello") + 1);
      close(fd[1]);
  } else {
      close(fd[1]);
      read(fd[0], buf, sizeof(buf));
      printf("received: %s\n", buf);
      close(fd[0]);
  }
  return 0;
  </code></pre>
  
  <p>The output is unexpectedly (or is it not?) <code>received: hello</code>.
  Same output if I replace the call to sleep() by a <code>for (volatile int i = 0; i &lt; some_big_int; ++i);</code> loop.
  I do not think that the call to <code>read()</code> will block my parent process until child writes at the other end of the pipe, but I cannot explain this behaviour though. Any hint?</p>