select.2 (2010 09)
s
select(2) select(2)
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
for the pipe, OR there are no readers left for the pipe.
select() returns the same results for a pipe
whether a file descriptor associated with the read-only end or the write-only end of the pipe is used, since
both file descriptors refer to the same underlying pipe. So a select() of a read-only file descriptor that
is associated with a pipe can return ready to write, even though that particular file descriptor cannot be
written to.
File descriptor masks of type fd_set can be initialized and tested with
FD_CLR(), FD_ISSET(),
FD_SET(), and FD_ZERO(). It is unspecified whether each of these is a macro or a function. If a
macro definition is suppressed in order to access an actual function, or a program defines an external
identifier with any of these names, the behaviour is undefined.
FD_CLR(fd, &fdset) Clears the bit for the file descriptor fd in the file descriptor set fdset .
FD_ISSET(fd, &fdset) Returns a non-zero value if the bit for the file descriptor fd is set in the
file descriptor set pointed to by fdset , and 0 otherwise.
FD_SET(fd, &fdset) Sets the bit for the file descriptor fd in the file descriptor set fdset .
FD_ZERO(&fdset) Initializes the file descriptor set fdset to have zero bits for all file descrip-
tors. The behaviour of these macros is undefined if the fd argument is
less than 0 or greater than or equal to FD_SETSIZE.
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: September 2010