M
Mark Seger
I have some code I had written awhile back (on perl 5.6 and redhat 9)
that used ualarm to wake me up every second and it worked really nicely.
However I've more recently dug into just how accurate that timer is
and was disappointed, especially on a cominaction of rhel4/u4 and perl
5.8.5. In fact, I see my code waking up almost 0.001 seconds later on
each subsequent interval.
Going back and rereading the manpage for Time:HiRes I spotted a comment
that the relationship between sigalarm and sleep are unspecified so I
changed my code to use setitimer() and it behaves the same way.
So my question is, is this a perl thing or a system thing? Or am I just
doing something silly. Here's what my code looks like:
use Time::HiRes qw(ITIMER_REAL);
$SIG{"ALRM"}= sub {};
Time::HiRes::setitimer(ITIMER_REAL, 1, 1);
while(1)
{
($intSeconds, $intUsecs)=Time::HiRes::gettimeofday();
printf("%d.%06d\n", $intSeconds, $intUsecs);
sleep 2;
}
and here's what it produces:
[root@cag-dl145-02 collectl]# ./alarm2-test.pl
1168452960.360707
1168452961.361269
1168452962.362297
1168452963.363291
I also tried using "select(undef, undef, undef, 2)" instead of the sleep
but that didn't make any difference.
-mark
that used ualarm to wake me up every second and it worked really nicely.
However I've more recently dug into just how accurate that timer is
and was disappointed, especially on a cominaction of rhel4/u4 and perl
5.8.5. In fact, I see my code waking up almost 0.001 seconds later on
each subsequent interval.
Going back and rereading the manpage for Time:HiRes I spotted a comment
that the relationship between sigalarm and sleep are unspecified so I
changed my code to use setitimer() and it behaves the same way.
So my question is, is this a perl thing or a system thing? Or am I just
doing something silly. Here's what my code looks like:
use Time::HiRes qw(ITIMER_REAL);
$SIG{"ALRM"}= sub {};
Time::HiRes::setitimer(ITIMER_REAL, 1, 1);
while(1)
{
($intSeconds, $intUsecs)=Time::HiRes::gettimeofday();
printf("%d.%06d\n", $intSeconds, $intUsecs);
sleep 2;
}
and here's what it produces:
[root@cag-dl145-02 collectl]# ./alarm2-test.pl
1168452960.360707
1168452961.361269
1168452962.362297
1168452963.363291
I also tried using "select(undef, undef, undef, 2)" instead of the sleep
but that didn't make any difference.
-mark