select.2 (2012 03)
s
select(2) select(2)
If the readfds argument is not a null pointer, it points to an object of type fd_set that on input specifies
the file descriptors to be checked for being ready to read, and on output indicates which file descriptors
are ready to read.
If the writefds argument is not a null pointer, it points to an object of type fd_set that on input specifies
the file descriptors to be checked for being ready to write, and on output indicates which file descriptors
are ready to write.
If the errorfds argument is not a null pointer, it points to an object of type fd_set that on input specifies
the file descriptors to be checked for error conditions pending, and on output indicates which file descrip-
tors have error conditions pending.
On successful completion, the objects pointed to by the readfds , writefds , and errorfds arguments are
modified to indicate which file descriptors are ready for reading, ready for writing, or have an error condi-
tion pending, respectively. For each file descriptor less than nfds , the corresponding bit will be set on
successful completion if it was set on input and the associated condition is true for that file descriptor.
If the timeout argument is not a null pointer, it specifies a maximum interval to wait for the selection to
complete. The timeout argument points to an object of type
struct timespec for pselect(), and to
an object of type
struct timeval for
select(). If the members of these structures are 0,
pselect() or select() will not block. If the timeout argument is a null pointer,
pselect() or
select() will block until an event causes one of the masks to be returned with a valid (non-zero) value.
If the time limit expires before any event occurs that would cause one of the masks to be set to a non-zero
value, pselect() or select() completes successfully and returns 0.
Implementations may place limitations on the maximum timeout interval supported. On all implementa-
tions, the maximum timeout interval supported will be at least 31 days. If the timeout argument specifies
a timeout interval greater than the implementation-dependent maximum value, the maximum value will
be used as the actual timeout value. Implementations may also place limitations on the granularity of
timeout intervals. If the requested timeout interval requires a finer granularity than the implementation
supports, the actual timeout interval will be rounded up to the next supported value.
If sigmask is not a null pointer, then the
pselect() function shall replace the signal mask of the pro-
cess by the set of signals pointed to by sigmask before examining the descriptors, and shall restore the
signal mask of the process before returning.
If the readfds , writefds , and errorfds arguments are all null pointers and the timeout argument is not a
null pointer,
pselect() or select() blocks for the time specified, or until interrupted by a signal. If
the readfds , writefds , and errorfds arguments are all null pointers and the timeout argument is a null
pointer, pselect() or select() blocks until interrupted by a signal.
File descriptors associated with regular files always select true for ready to read, ready to write, and
error conditions.
On failure, the objects pointed to by the readfds , writefds , and errorfds arguments are not modified. If
the timeout interval expires without the specified condition being true for any of the specified file descrip-
tors, the objects pointed to by the readfds , writefds , and errorfds arguments have all bits set to 0.
Ttys and sockets are ready for reading if a read() would not block for one or more of the following rea-
sons:
• input data is available.
• an error condition exists, such as a broken pipe, no carrier, or a lost connection.
Similarly, ttys and sockets are ready for writing if a
write() would not block for one or more of the fol-
lowing reasons:
• output data can be accepted.
• an error condition exists, such as a broken pipe, no carrier, or a lost connection.
TCP sockets select true on reads only for normal data. They do not select true on reads if out-of-band
data ("urgent" data) arrives.
TCP sockets select true on exceptions for out-of-band data.
AF_CCITT sockets select true on reads for normal and out-of-band data and information, including
supervisory frames.
Pipes are ready for reading if there is any data in the pipe, or if there are no writers left for the pipe.
Pipes are ready for writing if there is room for more data in the pipe AND there are one or more readers
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: March 2012