> When you run select() on stdin and when the end of file for stdin is
> reached (either by typing Ctrl+D at the console or when EOF of a
> file redirected as stdin is reached), select signals that stdin is
> ready for reading. Doing a read() then returns 0. If you run
> select() again on stdin, it still signals that stdin is ready for
> reading. Why is that so?
It's not signalling that it's ready for reading. It's signalling that
if you do a read() on the descriptor, the call will not block. The
descriptor could be some random number, which has never been
associated with any I/O device, and select() would say the same thing,
because if you tried to do a read() on it, it won't block.
See, for example
"A descriptor shall be considered ready for reading when a call to
an input function with O_NONBLOCK clear would not block, whether or
not the function would transfer data successfully. (The function
might return data, an end-of-file indication, or an error other
than one indicating that it is blocked, and in each of these cases
the descriptor shall be considered ready for reading.)
A descriptor shall be considered ready for writing when a call to
an output function with O_NONBLOCK clear would not block, whether
or not the function would transfer data successfully."