<div dir="ltr">On Fri, May 17, 2013 at 2:59 PM, devendra.aaru <span dir="ltr"><<a href="mailto:devendra.aaru@gmail.com" target="_blank">devendra.aaru@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello,<br>
<br>
<br>
The Select system call has given the timeout of 100 msec and but its<br>
expired after 115 msecs.<br>
<br>
I have no fds to read, and just wanted to use select as the timer to<br>
timeout and so some stuff after the timeout happen.<br>
<br>
code:<br>
<br>
#include <stdio.h><br>
#include <sys/stat.h><br>
#include <sys/types.h><br>
#include <sys/select.h><br>
<br>
main()<br>
{<br>
int ret;<br>
<br>
struct timeout tv;<br>
<br>
tv.tv_sec = 0;<br>
tv.tv_usec = 100000;<br>
<br>
while (1) {<br>
ret = select(5, 0, 0, 0, &tv);<br>
if (ret == 0) {<br>
struct timeval t;<br>
gettimeofday(&t, 0);<br>
<br>
printf("sec = %d-usec = %d\n", t.tv_sec, t.tv_usec);<br>
}<br>
}<br>
}<br>
<br>
<br>
my kernel is older, 2.6.23.<br>
<br>
<br>
thanks,<br></blockquote><div><br></div><div style>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.</div>
<div> </div></div></div><div class="gmail_extra"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">The </span><i style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">timeout</i><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"> argument specifies the minimum interval that </span><b style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">select</b><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">() 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 </span><i style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">timeval</i><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"> structure are zero, then </span><b style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">select</b><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">() returns immediately. (This is useful for polling.) If </span><i style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">timeout</i><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"> is NULL (no timeout), </span><b style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">select</b><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">() can block indefinitely.</span><br>
</div><div class="gmail_extra"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div class="gmail_extra" style><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">Regards,</span></div>
<div class="gmail_extra" style><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">Victor.</span></div></div>