title: How to check if stdin is still opened without blocking?
body: <p>I need my program written in pure C to stop execution when stdin is closed.</p>
  
  <p>There is indefinite work done in program main cycle, and there is no way I can use blocking checks (like <code>getc()</code>) there (no data is supposed to arrive on stdin - it just stays opened for unknown time).</p>
  
  <p>I intend to use described functionality in realization of network daemon hosted in inetd, xinetd or their analogs - it should emit data on stdout while connection stays opened and correctly finish work when it closes. Now my program is killed by hosting service as it won't stop after connection termination.</p>
  
  <p>I wonder if <code>fctntl()</code> with <code>O_NONBLOCK</code> flag applied to stdin descriptor would allow me to use <code>read()</code> function in non-blocking mode? Should I use <code>select()</code> somehow?</p>
  
  <p>P.S. The data is not supposed but might arrive to stdin. A way of non-blocking readout woould be an answer for the question.</p>