Jump to content

select (Unix)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mpeg4codec (talk | contribs) at 21:17, 23 June 2007 (cleaned up wording in introduction paragraph). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

select is a system call for polling multiple file descriptors. In C programming, it is declared in the header file sys/select.h or unistd.h. Those files and sys/time.h must be included to use select.

int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout);

argument description
nfds how many file descriptors to check
readfds array of fd_set types holding the file descriptors to be checked for being ready to read, and on output indicates which file descriptors are ready to read. Can be NULL.
writefds array of fd_set types holding the file descriptors to be checked for being ready to write, and on output indicates which file descriptors are ready to write. Can be NULL.
errorfds array of fd_set types holding the file descriptors to be checked for error conditions pending, and on output indicates which file descriptors have error conditions pending. Can be NULL.
timeout structure of type struct timeval that specifies a maximum interval to wait for the selection to complete. If the timeout argument points to an object of type struct timeval whose members are 0, select() does not block. If the timeout argument is a null pointer, select() blocks until an event causes one of the masks to be returned with a valid (non-zero) value.

External references