Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "select" do when nfds is 0?

Tags:

c

linux

int select(int nfds, 
           fd_set *readfds, 
           fd_set *writefds, 
           fd_set *exceptfds, 
           struct timeval *timeout);

The first parameter of select, nfds, is supposed to be the maximum file descriptor plus 1, which should be at least 1.
But I have seen some codes set nfds to be 0, is this usage legal?
Plus, the return value of select is set to EINVAL when nfds is negative or timeout contains invalid value. Again, it does not specify what happened when nfds is 0.

like image 891
Yu Hao Avatar asked Dec 06 '22 07:12

Yu Hao


1 Answers

It is possible to use select as an alternative for sleep. I believe it is achieved by specyfying all parameters as 0/NULL except timeout. Consult

Why use select() instead of sleep()?

like image 172
Dariusz Avatar answered Dec 14 '22 09:12

Dariusz