I want to use the select()
function to wait for 1 second, as my program uses signals to control stuff, so sleep()
would return prematurely. The weird thing is that when using select()
it also returns prematurely.
I am calling select like this
struct timeval timeout;
timeout.tv_sec = 10;
timeout.tv_usec = 1000000;
select (0 ,NULL, NULL, NULL, &timeout);
but whenever a signal arrives, it returns (I am using a nano second timer for the signal)
Anyone knows why?
Try something like this:
The "remaining time" pointer to
nanosleep
will take care of letting you restart the sleep with the necessary amount of remaining time if it gets interrupted.man 7 signal
says:Generally, checking if the return value is -1 and errno == EINTR and then re-calling the function is the right way to correct for this.