timer intervals coming up short



This program is a daemon waiting connections so it can fork a worker child.
That much is relatively classic. But I also included a timer wakeup every
one minute, with the interval calculated from the time of day value to keep
this intervals from from creeping longer. Thus it is syncronzied with the
clock, having only some jitter depending on system loads, etc.

Usually, the wakeup is just a tiny fraction of a second late, which can be
expected. But I sometimes it actually wakes up early. Then I end up with
two wakeups at the same top of minute.

In the following, the 2nd wakeup should have been at 1160845890 seconds,
but was at least 337 microseconds before that time. So in this case it
scheduled the next setitimer() for 337 microseconds later.

=============================================================================
--- SIGALRM (Alarm clock) ---
rt_sigreturn(0x5) = -1 EINTR (Interrupted system call)
rt_sigprocmask(SIG_SETMASK, ~[], NULL, 8) = 0
getppid() = 2392
gettimeofday({1160845830, 209}, NULL) = 0
setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={59, 999790}}, NULL) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
accept(3, 0xbffff540, [16]) = ? ERESTARTSYS (To be restarted)
--- SIGALRM (Alarm clock) ---
rt_sigreturn(0x5) = -1 EINTR (Interrupted system call)
rt_sigprocmask(SIG_SETMASK, ~[], NULL, 8) = 0
getppid() = 2392
gettimeofday({1160845889, 999662}, NULL) = 0
setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 337}}, NULL) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
accept(3, 0xbffff540, [16]) = ? ERESTARTSYS (To be restarted)
--- SIGALRM (Alarm clock) ---
rt_sigreturn(0x5) = -1 EINTR (Interrupted system call)
rt_sigprocmask(SIG_SETMASK, ~[], NULL, 8) = 0
getppid() = 2392
gettimeofday({1160845890, 9254}, NULL) = 0
setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={59, 990745}}, NULL) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
=============================================================================

This isn't actually causing any problems. Any processing that needs to
happen at specific times would not be run prematurely because it would
based on what time it is. So something to be run at 1160845890 above
would not have been run in the 2nd wakeup above.

But I am curious why this happens. Is there a worst case limit which it
could never go beyond?

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2006-10-14-1757@xxxxxxxx |
|------------------------------------/-------------------------------------|
.