title: Detect whether a FIFO is closed in C using poll()
body: <p>I have been researching around using poll() to detect whether an FIFO has been closed from another process, but haven't been able to get anything to work. The polling section of my code is as follows:</p>
  <pre><code>            int poll_return = poll(pfds, 2, POLL_TIMEOUT);
              printf(&quot;POLL CALLED\n&quot;);
  
              if (pfds[0].revents != 0) {
                  printf(&quot;Events: %d%d%d\n&quot;, 
                  (pfds[0].revents &amp; POLLIN), 
                  (pfds[0].revents &amp; POLLHUP), 
                  (pfds[0].revents &amp; POLLERR));
  
                  if (pfds[0].revents &amp; POLLHUP) {
                      printf(&quot;FIFO has been closed&quot;);
                  }
              }
  </code></pre>
  <p>For some reason, the code prints:</p>
  <p>POLL CALLED</p>
  <p>Events: 000</p>