Select doesn't work correctly on EC2

Hi

I found select's timeout doesn't work correctly on EC2. This problem is reproduced by following way.

1. Create an EC2 instance using 118940168514/FreeBSD/EC2 8.3-RELEASE amd64/HVM(AMI-6c1dac6d).
2. Run following commands on the instance.
$ vi testselect.c
Code:
#include <stdio.h>
#include <sys/select.h>
int main(){
        struct timeval t;
        t.tv_sec = 5;
        t.tv_usec = 0;
        select(0, NULL, NULL, NULL, &t);
        return 0;
}
Code:
$ gcc testselect.c
$ time ./a.out
        8.61 real         0.00 user         0.00 sys
How can I fix this problem?

Thanks:)
 
Don't double post yamaneko, if a post is in the wrong place a mod will move it.
 
From select(2):
Code:
     If timeout is not a null pointer, it specifies the maximum interval to
     wait for the selection to complete.  [b]System activity can lengthen the
     interval by an indeterminate amount.[/b]
 
If you want to get more precision and efficiency you should use poll() or even better (but not so portable) kqueue(). Select syscall has been around almost as long as UNIX itself and is not the most advanced way to handle I/O.
 
Back
Top