select.2 (2012 03)
s
select(2) select(2)
nfds argument is greater than FD_SETSIZE.
[EINTR] The function was interrupted before any of the selected events occurred and before the
timeout interval expired. If
SA_RESTART has been set for the interrupting signal, it is
implementation-dependent whether the function restarts or returns with [EINTR].
[EFAULT] One or more of the pointers was invalid. The reliable detection of this error is implemen-
tation dependent.
[EINVAL] An invalid timeout interval was specified. Valid values for the number of nanoseconds
(in
struct timespec) should be a non-negative integer less than 1,000,000,000. For
the number of microseconds (in struct timeval), a non-negative integer less than
1,000,000 should be used. Seconds should be specified using a non-negative integer.
[EINVAL] The nfds argument is less than 0, or is greater than or equal to the value of
MAXFUPLIM,
which specifies the absolute maximum number of files a process can have open at one
time. If the resource limit
RLIMIT_NOFILE
for a process is less than or equal to 2048,
MAXFUPLIM is considered to be 2048.
[EINVAL] One of the specified file descriptors refers to a STREAM or multiplexer that is linked
(directly or indirectly) downstream from a multiplexer.
EXAMPLES
The following call to select() checks if any of 4 terminals are ready for reading. select()
times
out after 5 seconds if no terminals are ready for reading. Note that the code for opening the terminals or
reading from the terminals is not shown in this example. Also, note that this example must be modified if
the calling process has more than 32 file descriptors open. Following this first example is an example of
select with more than 32 file descriptors.
#define MASK(f) (1 << (f))
#define NTTYS 4
int tty[NTTYS];
int ttymask[NTTYS];
int readmask = 0;
int readfds;
int nfound, i;
struct timeval timeout;
/* First open each terminal for reading and put the
* file descriptors into array tty[NTTYS]. The code
* for opening the terminals is not shown here.
*/
for (i=0; i < NTTYS; i++) {
ttymask[i] = MASK(tty[i]);
readmask |= ttymask[i];
}
timeout.tv_sec = 5;
timeout.tv_usec = 0;
readfds = readmask;
/* select on NTTYS+3 file descriptors if stdin, stdout
* and stderr are also open
*/
if ((nfound = select (NTTYS+3, &readfds, 0, 0, &timeout)) == -1)
perror ("select failed");
else if (nfound == 0)
printf ("select timed out \n");
else for (i=0; i < NTTYS; i++)
if (ttymask[i] & readfds)
/* Read from tty[i]. The code for reading
* is not shown here.
*/
else printf ("tty[%d] is not ready for reading \n",i);
4 Hewlett-Packard Company − 4 − HP-UX 11i Version 3: March 2012