select
Function
Enable I/O multiplexing
Function Prototype
totalFds = select(nfds, readfds, writefds, errorfds, timeout)nfds- the range of file descriptors to checkreadfds- a bit map, set bit to check whether file descriptor is ready for readingwritefds- set bit to check whether file descriptors is ready for writingerrorfds- bit map to check for errorstimeout- how long to wait before stop blocking the processtotalFds- number of ready descriptors, 0 for timeout, negative for error
How does it works?

- When we call
select, the process is put to sleep and the kernel will help us monitor the file descriptor we specify - Once a file descriptor is ready or timeout, the kernel will revise
readfds,writefds, orerrorfdsmaking only the file descriptor which is ready to be1 - The kernel will then awake the process, then we can scan through
readfds,writefds, anderrorfdsto find which file descriptor is ready - Eventually, the process can operate on the file
Disadvantages
- To tell the process which file descriptor is available,
selectneed to modifyreadfds,writefds, … - If we only need to monitor fd 1000, we still need to set
nfdsto 1001