Nano sleep command in Perl
Im trying a perl script with use Time::H开发者_运维知识库iRes qw(gettimeofday tv_interval usleep);
usleep(9.098888) usleep(9.091111)
my script is containing, above commands also, I need a clarification that, how much round of usleep will do? how to use nanosleep instead? (how much precition it would be in?)
Thanks in advance, Saranyya
The answer to this depends on your platform.
On my own Linux system, Perl's usleep
already calls nanosleep
:
$ strace -- perl -le 'use Time::HiRes; Time::HiRes::usleep(1);' 2>&1 | tail
open("/usr/share/perl/5.10/Exporter/Heavy.pm", O_RDONLY) = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff375a5740) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(4, 0, SEEK_CUR) = 0
read(4, "package Exporter::Heavy;\n\nuse st"..., 4096) = 4096
read(4, "nd without a leading &.\n\t # ("..., 4096) = 2250
read(4, "", 4096) = 0
close(4) = 0
close(3) = 0
nanosleep({0, 1000}, NULL) = 0
exit_group(0) = ?
(Actually, I am pretty sure the C library's usleep
calls nanosleep
internally.)
The actual resolution you can expect depends on your specific platform. These sleep functions can have a resolution measured in milliseconds (especially for long sleeps), and they always try to round up.
If you specify the exact version of your hardware and operating system, someone might be able to track down the effective resolution of nanosleep
for you.
精彩评论