SELECT(2)

NAME
select - synchronous I/O multiplexing

SYNOPSIS
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int select(int numfds, fd_set *readfds, fd_set *writefds , fd_set *exceptfds, struct timeval * timeout);

FD_CLR(int fd, fd_set *set);
FD_ISSET(int fd, fd_set *set);
FD_SET(int fd, fd_set *set);
FD_ZERO(fd_set * set);

DESCRIPTION
Select causes the calling process to sleep until a file descriptor in readfds, writefds, or exceptfds becomes available for reading, writing, or has an exception raised respectively, or until the time limit set by timeout has elapsed. On exit, select indicates file descriptors that have become available by modifying readfds, writefds, and exceptfds in place. Timeout is also updated to reflect the amount of time remaining. Several macros are provided for manipulating file descriptor sets. FD_SET and FD_CLR add and remove fd to/from set, FD_ZERO clears set, and FD_ISSET returns nonzero fd is in set.

RETURN VALUE
On success, select returns the number of descriptors contained in the descriptor sets. On error, -1 is returned, and errno is set appropriately.

ERRORS

EBADF
    An invalid file descriptor was given in one of the sets.

EINTR
    A non blocked signal was caught.

EINVAL
    nd is negative.

ENOMEM
    select was unable to allocate memory for internal tables.

NOTES
The Linux behavior with respect to timeout differs from other unices that don't modify it.

SEE ALSO
accept(2), connect(2), read(2), recv(2), send(2), write(2)