question on select

Hello All,

The linux call 'select' takes first argument as maxfds+1. Does this have any significance. Why is that 'maxfds+1'?

Thanks in advance
nkumar
select, as you might know, gets the sub-set of file descriptors that are SET either for read/write. So maxfds + 1, specifies in which range from 0 should it search for set of file descriptors that are ready for either read/write.

Hope this helps !
In other words:

Look at the file descriptors you put in the three FD_SETs, pick the highest numbered one, and add one to it.

So if you are selecting on the FD_SET {1, 2, 4, 5, 7, 9 }, then set the first parameter to 9 + 1 = 10.
So is it because the range start from 0 we need to set the first argument as maxfds+1?
If you see the source code of sys_select , you can find the core work related to this 'maxfds+1' is in function core_sys_select.

It prepare a bit-map for select, which need the kmalloc size.
Topic archived. No new replies allowed.