Share on Facebook Share on Twitter Email
Answers.com

Select

 
Wikipedia: Select (Unix)

select is a system call for polling the status of 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 the maximum file descriptor across all the sets, plus 1
readfds fd_set type 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 fd_set type 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 fd_set type 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 NULL, select() blocks until an event causes one of the masks to be returned with a valid (non-zero) value.

To manipulate the fd_set type arguments, the four FD_SET(), FD_CLR(), FD_ZERO() and FD_ISSET() macros can be used.

The function returns the total number of bits set in readfds, writefds and errorfds, the value of zero if the timeout expired and -1 on error.

Problems with select(2) are, compared to poll(2), that the fd sets are of finite size, which means that file descriptors with a high enough value (fd sets have space for 1024 bits in glibc, for example) cannot be used with select.

External references


Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
 
 
Learn More
Sel
choose
nominate

What is a selection of detail? Read answer...
Definition of selection? Read answer...
What is food selection? Read answer...

Help us answer these
What was a selection?
What are selections?
What is selective?

Post a question - any question - to the WikiAnswers community:

 

Copyrights:

Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Select (Unix)" Read more