int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
Question:
Irrespective of timeout
argument passed,
Does select()
occupy CPU cycles, until any file descriptor is ready?
It should not be; any decent OS (including Linux, Windows and more) will suspend the process if there are no FDs immediately available. CPU cycles between that happening and the next FD being available are available for use by other threads/processes in the system, and/or the system idle loop. Normally, the OS is arranged as an event driven system, so there is no need to repeatedly check for changes in select: the cause of (eg data being available to read) will result in all active selects being informed of this as a side-effect.
However, be aware that select() is usually a C-library wrapper function for the actual implementation.
Be aware that you must clear all outstanding available FDs on each successful return, because if not you're going to incur the the system call overhead without good reason, and additionally risk 'starvation'.
What could cause busy-wait behaviour is setting the timeout to a near-zero value and then looping. I have seen this done in some cases because the programmer thought they needed to check something not visible as an FD