title: How to see if a pipe is empty
body: <p>Assuming a pipe,</p>
  
  <pre><code>int pipe_fd[2];
  pipe(pipe_fd);
  </code></pre>
  
  <p>We fork, and expect that one process will write into the pipe at an arbitrary time. In one of the processes, we want to be able to check the contents of the pipe without blocking. </p>
  
  <p>i.e. While a typical read will block if nothing is present and the write end remains open. I want to go do other stuff and potentially even read a bit at a time, do some stuff, and then check back to see if there's more, a la: </p>
  
  <pre><code>close(pipe_fd[1]);
  
  while(1){
      if(/**Check pipe contents**/){
          int present_chars = 0;    
  
          while( read(pipe_fd[0],&amp;buffer[present_chars],1) != 0)
              ++present_chars;
  
          //do something
  
      }
      else
          //do something else
  }
  </code></pre>