title: read from pipe is blocking
body: <p>I'm reading an unkown number of messages from a pipe. However, read is blocking. I've tried the below code to set the reads to non-blocking. However, this resulted in read errors and processes not reading all the way through.</p>
  
  <pre><code>// Set pipe to non-blocking
  sleep(5);
  fcntl(fd[index][0], F_SETFL, O_NONBLOCK);
  </code></pre>
  
  <p>How can I successfully read and print all the messages, without the program hanging?
  Here is the code that causes the issue:</p>
  
  <pre><code>// Read every message
  while((n = read(fd[index][0], &amp;mymsg, sizeof(int))) == sizeof(int))
      printf("process%d  has received a message from process%d\n", index, mymsg);
  </code></pre>