title: Detect when reader closes named pipe (FIFO)
body: <p>Is there any way for a writer to know that a reader has closed its end of a named pipe (or exited), <em>without</em> writing to it?</p>
  
  <p>I need to know this because the initial data I write to the pipe is different; the reader is expecting an initial header before the rest of the data comes. </p>
  
  <p>Currently, I detect this when my <code>write()</code> fails with <code>EPIPE</code>. I then set a flag that says "next time, send the header". However, it is possible for the reader to close and re-open the pipe before I've written anything. In this case, I never realize what he's done, and don't send the header he is expecting.</p>
  
  <p>Is there any sort of async event type thing that might help here? I'm not seeing any signals being sent.</p>
  
  <p><sub>Note that I haven't included any language tags, because this question should be considered language-agnostic.  My code is Python, but the answers should apply to C, or any other language with system call-level bindings.</sub></p>