select call takes more time than the given timeout

devendra.aaru devendra.aaru at gmail.com
Fri May 17 07:59:08 EDT 2013


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,



More information about the Kernelnewbies mailing list