I need my program written in pure C to stop execution when stdin is closed.
There is indefinite work done in program main cycle, and there is no way I can use blocki
Yes, you can use select
(with a zero timeout). You don't need to set the file descriptor non-blocking, though - if select
tells you that the file descriptor is readable, then a read
on it will definitely not block.
So, poll file descriptor 0 occaisionally with select
, and if it's readable, read
it. If read
returns 0, then that means it's been closed.