When select is called, it uses the first to fourth parameters to determine which FD to monitor for what. Note that the same FD can appear in any number of sets. select also checks the fifth parameter to see if a time out period is defined.
select returns (unblocks) iff at least one of the following conditions is true:
select also has a return value. The return value is the number of monitored FDs that has pending bytes to read, room for one byte to write or an exception. A single FD can be counted up to three times if it is in all three sets, and all three reasons are satisfied. One can also say that the return value is the total number of elements in all returned sets.
This return value can be zero if select returns because of timing out.