⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 time::hires.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
.ie n .IP "alarm ( $floating_seconds\fR [, \f(CW$interval_floating_seconds ] )" 4.el .IP "alarm ( \f(CW$floating_seconds\fR [, \f(CW$interval_floating_seconds\fR ] )" 4.IX Item "alarm ( $floating_seconds [, $interval_floating_seconds ] )"The \f(CW\*(C`SIGALRM\*(C'\fR signal is sent after the specified number of seconds.Implemented using \f(CW\*(C`ualarm()\*(C'\fR.  The \f(CW$interval_floating_seconds\fR argumentis optional and will be zero if unspecified, resulting in \f(CW\*(C`alarm()\*(C'\fR\-likebehaviour.  This function can be imported, resulting in a nice drop-inreplacement for the \f(CW\*(C`alarm\*(C'\fR provided with perl, see the \*(L"\s-1EXAMPLES\s0\*(R" below..Sp\&\fB\s-1NOTE\s0 1\fR: With some combinations of operating systems and Perlreleases \f(CW\*(C`SIGALRM\*(C'\fR restarts \f(CW\*(C`select()\*(C'\fR, instead of interrupting it.This means that an \f(CW\*(C`alarm()\*(C'\fR followed by a \f(CW\*(C`select()\*(C'\fR may togethertake the sum of the times specified for the the \f(CW\*(C`alarm()\*(C'\fR and the\&\f(CW\*(C`select()\*(C'\fR, not just the time of the \f(CW\*(C`alarm()\*(C'\fR..SpNote that the interaction between alarms and sleeps is unspecified..ie n .IP "setitimer ( $which\fR, \f(CW$floating_seconds\fR [, \f(CW$interval_floating_seconds ] )" 4.el .IP "setitimer ( \f(CW$which\fR, \f(CW$floating_seconds\fR [, \f(CW$interval_floating_seconds\fR ] )" 4.IX Item "setitimer ( $which, $floating_seconds [, $interval_floating_seconds ] )"Start up an interval timer: after a certain time, a signal ($which) arrives,and more signals may keep arriving at certain intervals.  To disablean \*(L"itimer\*(R", use \f(CW$floating_seconds\fR of zero.  If the\&\f(CW$interval_floating_seconds\fR is set to zero (or unspecified), thetimer is disabled \fBafter\fR the next delivered signal..SpUse of interval timers may interfere with \f(CW\*(C`alarm()\*(C'\fR, \f(CW\*(C`sleep()\*(C'\fR,and \f(CW\*(C`usleep()\*(C'\fR.  In standard-speak the \*(L"interaction is unspecified\*(R",which means that \fIanything\fR may happen: it may work, it may not..SpIn scalar context, the remaining time in the timer is returned..SpIn list context, both the remaining time and the interval are returned..SpThere are usually three or four interval timers (signals) available: the\&\f(CW$which\fR can be \f(CW\*(C`ITIMER_REAL\*(C'\fR, \f(CW\*(C`ITIMER_VIRTUAL\*(C'\fR, \f(CW\*(C`ITIMER_PROF\*(C'\fR, or\&\f(CW\*(C`ITIMER_REALPROF\*(C'\fR.  Note that which ones are available depends: true\&\s-1UNIX\s0 platforms usually have the first three, but (for example) Win32and Cygwin have only \f(CW\*(C`ITIMER_REAL\*(C'\fR, and only Solaris seems to have\&\f(CW\*(C`ITIMER_REALPROF\*(C'\fR (which is used to profile multithreaded programs)..Sp\&\f(CW\*(C`ITIMER_REAL\*(C'\fR results in \f(CW\*(C`alarm()\*(C'\fR\-like behaviour.  Time is counted in\&\fIreal time\fR; that is, wallclock time.  \f(CW\*(C`SIGALRM\*(C'\fR is delivered whenthe timer expires..Sp\&\f(CW\*(C`ITIMER_VIRTUAL\*(C'\fR counts time in (process) \fIvirtual time\fR; that is,only when the process is running.  In multiprocessor/user/CPU systemsthis may be more or less than real or wallclock time.  (This time isalso known as the \fIuser time\fR.)  \f(CW\*(C`SIGVTALRM\*(C'\fR is delivered when thetimer expires..Sp\&\f(CW\*(C`ITIMER_PROF\*(C'\fR counts time when either the process virtual time or whenthe operating system is running on behalf of the process (such as I/O).(This time is also known as the \fIsystem time\fR.)  (The sum of usertime and system time is known as the \fI\s-1CPU\s0 time\fR.)  \f(CW\*(C`SIGPROF\*(C'\fR isdelivered when the timer expires.  \f(CW\*(C`SIGPROF\*(C'\fR can interrupt system calls..SpThe semantics of interval timers for multithreaded programs aresystem-specific, and some systems may support additional intervaltimers.  For example, it is unspecified which thread gets the signals.See your \f(CW\*(C`setitimer()\*(C'\fR documentation..ie n .IP "getitimer ( $which )" 4.el .IP "getitimer ( \f(CW$which\fR )" 4.IX Item "getitimer ( $which )"Return the remaining time in the interval timer specified by \f(CW$which\fR..SpIn scalar context, the remaining time is returned..SpIn list context, both the remaining time and the interval are returned.The interval is always what you put in using \f(CW\*(C`setitimer()\*(C'\fR..ie n .IP "clock_gettime ( $which )" 4.el .IP "clock_gettime ( \f(CW$which\fR )" 4.IX Item "clock_gettime ( $which )"Return as seconds the current value of the \s-1POSIX\s0 high resolution timerspecified by \f(CW$which\fR.  All implementations that support \s-1POSIX\s0 highresolution timers are supposed to support at least the \f(CW$which\fR valueof \f(CW\*(C`CLOCK_REALTIME\*(C'\fR, which is supposed to return results close to theresults of \f(CW\*(C`gettimeofday\*(C'\fR, or the number of seconds since 00:00:00:00January 1, 1970 Greenwich Mean Time (\s-1GMT\s0).  Do not assume that\&\s-1CLOCK_REALTIME\s0 is zero, it might be one, or something else.Another potentially useful (but not available everywhere) value is\&\f(CW\*(C`CLOCK_MONOTONIC\*(C'\fR, which guarantees a monotonically increasing timevalue (unlike \fItime()\fR, which can be adjusted).  See your systemdocumentation for other possibly supported values..ie n .IP "clock_getres ( $which )" 4.el .IP "clock_getres ( \f(CW$which\fR )" 4.IX Item "clock_getres ( $which )"Return as seconds the resolution of the \s-1POSIX\s0 high resolution timerspecified by \f(CW$which\fR.  All implementations that support \s-1POSIX\s0 highresolution timers are supposed to support at least the \f(CW$which\fR valueof \f(CW\*(C`CLOCK_REALTIME\*(C'\fR, see \*(L"clock_gettime\*(R"..ie n .IP "clock_nanosleep ( $which\fR, \f(CW$nanoseconds\fR, \f(CW$flags = 0)" 4.el .IP "clock_nanosleep ( \f(CW$which\fR, \f(CW$nanoseconds\fR, \f(CW$flags\fR = 0)" 4.IX Item "clock_nanosleep ( $which, $nanoseconds, $flags = 0)"Sleeps for the number of nanoseconds (1e9ths of a second) specified.Returns the number of nanoseconds actually slept.  The \f(CW$which\fR is the\&\*(L"clock id\*(R", as with \fIclock_gettime()\fR and \fIclock_getres()\fR.  The flagsdefault to zero but \f(CW\*(C`TIMER_ABSTIME\*(C'\fR can specified (must be exportedexplicitly) which means that \f(CW$nanoseconds\fR is not a time interval(as is the default) but instead an absolute time.  Can sleep for morethan one second.  Can also sleep for zero seconds, which often workslike a \fIthread yield\fR.  See also \f(CW\*(C`Time::HiRes::sleep()\*(C'\fR,\&\f(CW\*(C`Time::HiRes::usleep()\*(C'\fR, and \f(CW\*(C`Time::HiRes::nanosleep()\*(C'\fR..SpDo not expect \fIclock_nanosleep()\fR to be exact down to one nanosecond.Getting even accuracy of one thousand nanoseconds is good..IP "\fIclock()\fR" 4.IX Item "clock()"Return as seconds the \fIprocess time\fR (user + system time) spent bythe process since the first call to \fIclock()\fR (the definition is \fBnot\fR\&\*(L"since the start of the process\*(R", though if you are lucky these timesmay be quite close to each other, depending on the system).  What thismeans is that you probably need to store the result of your first callto \fIclock()\fR, and subtract that value from the following results of \fIclock()\fR..SpThe time returned also includes the process times of the terminatedchild processes for which \fIwait()\fR has been executed.  This value issomewhat like the second value returned by the \fItimes()\fR of core Perl,but not necessarily identical.  Note that due to backwardcompatibility limitations the returned value may wrap around at about2147 seconds or at about 36 minutes..IP "stat" 4.IX Item "stat".PD 0.IP "stat \s-1FH\s0" 4.IX Item "stat FH".IP "stat \s-1EXPR\s0" 4.IX Item "stat EXPR".PDAs \*(L"stat\*(R" in perlfunc but with the access/modify/change file timestampsin subsecond resolution, if the operating system and the filesystemboth support such timestamps.  To override the standard \fIstat()\fR:.Sp.Vb 1\&    use Time::HiRes qw(stat);.Ve.SpTest for the value of &Time::HiRes::d_hires_stat to find out whetherthe operating system supports subsecond file timestamps: a valuelarger than zero means yes. There are unfortunately no easyways to find out whether the filesystem supports such timestamps.\&\s-1UNIX\s0 filesystems often do; \s-1NTFS\s0 does; \s-1FAT\s0 doesn't (\s-1FAT\s0 timestampgranularity is \fBtwo\fR seconds)..SpA zero return value of &Time::HiRes::d_hires_stat means thatTime::HiRes::stat is a no-op passthrough for \fICORE::stat()\fR,and therefore the timestamps will stay integers.  The samething will happen if the filesystem does not do subsecond timestamps,even if the &Time::HiRes::d_hires_stat is non-zero..SpIn any case do not expect nanosecond resolution, or even a microsecondresolution.  Also note that the modify/access timestamps might havedifferent resolutions, and that they need not be synchronized, e.g.if the operations are.Sp.Vb 4\&    write\&    stat # t1\&    read\&    stat # t2.Ve.Spthe access time stamp from t2 need not be greater-than the modifytime stamp from t1: it may be equal or \fIless\fR..SH "EXAMPLES".IX Header "EXAMPLES".Vb 1\&  use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);\&\&  $microseconds = 750_000;\&  usleep($microseconds);\&\&  # signal alarm in 2.5s & every .1s thereafter\&  ualarm(2_500_000, 100_000);\&  # cancel that ualarm\&  ualarm(0);\&\&  # get seconds and microseconds since the epoch\&  ($s, $usec) = gettimeofday();\&\&  # measure elapsed time \&  # (could also do by subtracting 2 gettimeofday return values)\&  $t0 = [gettimeofday];\&  # do bunch of stuff here\&  $t1 = [gettimeofday];\&  # do more stuff here\&  $t0_t1 = tv_interval $t0, $t1;\&\&  $elapsed = tv_interval ($t0, [gettimeofday]);\&  $elapsed = tv_interval ($t0); # equivalent code\&\&  #\&  # replacements for time, alarm and sleep that know about\&  # floating seconds\&  #\&  use Time::HiRes;\&  $now_fractions = Time::HiRes::time;\&  Time::HiRes::sleep (2.5);\&  Time::HiRes::alarm (10.6666666);\&\&  use Time::HiRes qw ( time alarm sleep );\&  $now_fractions = time;\&  sleep (2.5);\&  alarm (10.6666666);\&\&  # Arm an interval timer to go off first at 10 seconds and\&  # after that every 2.5 seconds, in process virtual time\&\&  use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );\&\&  $SIG{VTALRM} = sub { print time, "\en" };\&  setitimer(ITIMER_VIRTUAL, 10, 2.5);\&\&  use Time::HiRes qw( clock_gettime clock_getres CLOCK_REALTIME );\&  # Read the POSIX high resolution timer.\&  my $high = clock_getres(CLOCK_REALTIME);\&  # But how accurate we can be, really?\&  my $reso = clock_getres(CLOCK_REALTIME);\&\&  use Time::HiRes qw( clock_nanosleep TIMER_ABSTIME );\&  clock_nanosleep(CLOCK_REALTIME, 1e6);\&  clock_nanosleep(CLOCK_REALTIME, 2e9, TIMER_ABSTIME);\&\&  use Time::HiRes qw( clock );\&  my $clock0 = clock();\&  ... # Do something.\&  my $clock1 = clock();\&  my $clockd = $clock1 \- $clock0;\&\&  use Time::HiRes qw( stat );\&  my ($atime, $mtime, $ctime) = (stat("istics"))[8, 9, 10];.Ve.SH "C API".IX Header "C API"In addition to the perl \s-1API\s0 described above, a C \s-1API\s0 is available forextension writers.  The following C functions are available in themodglobal hash:.PP.Vb 4\&  name             C prototype\&  \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-  \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\&  Time::NVtime     double (*)()\&  Time::U2time     void (*)(pTHX_ UV ret[2]).Ve.PPBoth functions return equivalent information (like \f(CW\*(C`gettimeofday\*(C'\fR)but with different representations.  The names \f(CW\*(C`NVtime\*(C'\fR and \f(CW\*(C`U2time\*(C'\fRwere selected mainly because they are operating system independent.(\f(CW\*(C`gettimeofday\*(C'\fR is Unix-centric, though some platforms like Win32 and\&\s-1VMS\s0 have emulations for it.).PPHere is an example of using \f(CW\*(C`NVtime\*(C'\fR from C:.PP.Vb 6\&  double (*myNVtime)(); /* Returns \-1 on failure. */\&  SV **svp = hv_fetch(PL_modglobal, "Time::NVtime", 12, 0);\&  if (!svp)         croak("Time::HiRes is required");\&  if (!SvIOK(*svp)) croak("Time::NVtime isn\*(Aqt a function pointer");\&  myNVtime = INT2PTR(double(*)(), SvIV(*svp));\&  printf("The current time is: %f\en", (*myNVtime)());.Ve.SH "DIAGNOSTICS".IX Header "DIAGNOSTICS".Sh "useconds or interval more than ...".IX Subsection "useconds or interval more than ..."In \fIualarm()\fR you tried to use number of microseconds or interval (alsoin microseconds) more than 1_000_000 and \fIsetitimer()\fR is not availablein your system to emulate that case..Sh "negative time not invented yet".IX Subsection "negative time not invented yet"You tried to use a negative time argument..Sh "internal error: useconds < 0 (unsigned ... signed ...)".IX Subsection "internal error: useconds < 0 (unsigned ... signed ...)"Something went horribly wrong\*(-- the number of microseconds that cannotbecome negative just became negative.  Maybe your compiler is broken?.SH "CAVEATS".IX Header "CAVEATS"Notice that the core \f(CW\*(C`time()\*(C'\fR maybe rounding rather than truncating.What this means is that the core \f(CW\*(C`time()\*(C'\fR may be reporting the timeas one second later than \f(CW\*(C`gettimeofday()\*(C'\fR and \f(CW\*(C`Time::HiRes::time()\*(C'\fR..PPAdjusting the system clock (either manually or by services like ntp)may cause problems, especially for long running programs that assumea monotonously increasing time (note that all platforms do not adjusttime as gracefully as \s-1UNIX\s0 ntp does).  For example in Win32 (and derivedplatforms like Cygwin and MinGW) the \fITime::HiRes::time()\fR may temporarilydrift off from the system clock (and the original \fItime()\fR)  by up to 0.5seconds. Time::HiRes will notice this eventually and recalibrate.Note that since Time::HiRes 1.77 the clock_gettime(\s-1CLOCK_MONOTONIC\s0)might help in this (in case your system supports \s-1CLOCK_MONOTONIC\s0)..SH "SEE ALSO".IX Header "SEE ALSO"Perl modules BSD::Resource, Time::TAI64..PPYour system documentation for \f(CW\*(C`clock\*(C'\fR, \f(CW\*(C`clock_gettime\*(C'\fR,\&\f(CW\*(C`clock_getres\*(C'\fR, \f(CW\*(C`clock_nanosleep\*(C'\fR, \f(CW\*(C`clock_settime\*(C'\fR, \f(CW\*(C`getitimer\*(C'\fR,\&\f(CW\*(C`gettimeofday\*(C'\fR, \f(CW\*(C`setitimer\*(C'\fR, \f(CW\*(C`sleep\*(C'\fR, \f(CW\*(C`stat\*(C'\fR, \f(CW\*(C`ualarm\*(C'\fR..SH "AUTHORS".IX Header "AUTHORS"D. Wegscheid <wegscd@whirlpool.com>R. Schertler <roderick@argon.org>J. Hietaniemi <jhi@iki.fi>G. Aas <gisle@aas.no>.SH "COPYRIGHT AND LICENSE".IX Header "COPYRIGHT AND LICENSE"Copyright (c) 1996\-2002 Douglas E. Wegscheid.  All rights reserved..PPCopyright (c) 2002, 2003, 2004, 2005, 2006, 2007 Jarkko Hietaniemi.  All rights reserved..PPThis program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -