man(1) Manual page archive

     SELECT(2)                                               SELECT(2)

          select - synchronous I/O multiplexing

          #include <sys/types.h>
          int select(nfds, readfds, writefds, milli);
          fd_set *readfds, *writefds;

          Select examines the IO descriptors specified by the bit
          masks readfds and writefds to see if they are ready for
          reading and/or writing respectively and returns, in place, a
          mask of those descriptors which are ready.  Only descriptors
          0 through nfds-1 are examined.  The total number of ready
          descriptors is returned.

          File descriptors referring to ordinary files and non-stream
          special files always appear ready.

          Milli is the maximum number of milliseconds to wait before
          giving up if no descriptors come active.  If no maximum wait
          is desired a very large integer can be given.  If milli is
          0, select returns whatever information is available without

          Either readfds or writefds may be null if no descriptors are
          interesting.  Readfds and writefds point to a structure con-
          taining a simple bit mask: file descriptor f is represented
          by the bit 1<<(f%N) in readfds->fds_bits[f/N], where N is
          the number of bits in an int (given by the constant expres-
          sion NBBY*NBPW). These macros manipulate the bits of mask s:

          FD_ZERO(s)     clear all bits

          FD_SET(n,s)    set bit n

          FD_CLR(n,s)    clear bit n

          FD_ISSET(n,s)  test bit n

          Milli is rounded up to the nearest second.
          Select is intended for use with streams; it does not work
          with non-stream special files that can block.