select call takes more time than the given timeout
Hello, The Select system call has given the timeout of 100 msec and but its expired after 115 msecs. I have no fds to read, and just wanted to use select as the timer to timeout and so some stuff after the timeout happen. code: #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/select.h> main() { int ret; struct timeout tv; tv.tv_sec = 0; tv.tv_usec = 100000; while (1) { ret = select(5, 0, 0, 0, &tv); if (ret == 0) { struct timeval t; gettimeofday(&t, 0); printf("sec = %d-usec = %d\n", t.tv_sec, t.tv_usec); } } } my kernel is older, 2.6.23. thanks,
On Fri, May 17, 2013 at 2:59 PM, devendra.aaru <devendra.aaru@gmail.com>wrote:
Hello,
The Select system call has given the timeout of 100 msec and but its expired after 115 msecs.
I have no fds to read, and just wanted to use select as the timer to timeout and so some stuff after the timeout happen.
code:
#include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/select.h>
main() { int ret;
struct timeout tv;
tv.tv_sec = 0; tv.tv_usec = 100000;
while (1) { ret = select(5, 0, 0, 0, &tv); if (ret == 0) { struct timeval t; gettimeofday(&t, 0);
printf("sec = %d-usec = %d\n", t.tv_sec, t.tv_usec); } } }
my kernel is older, 2.6.23.
thanks,
As the manual page for select specifies (see below) you should expect some delays due to kernel scheduling. If you need more precision you might wanna try something else. The *timeout* argument specifies the minimum interval that *select*() should block waiting for a file descriptor to become ready. (This interval will be rounded up to the system clock granularity, and kernel scheduling delays mean that the blocking interval may overrun by a small amount.) If both fields of the *timeval* structure are zero, then *select*() returns immediately. (This is useful for polling.) If *timeout* is NULL (no timeout), *select*() can block indefinitely. Regards, Victor.
participants (2)
-
devendra.aaru -
Victor Buciuc