Gawk/Extension-Sample-Time
Next: Extension Sample API Tests, Previous: Extension Sample Readfile, Up: Extension Samples [Contents][Index]
17.7.11 Extension Time Functions
CAUTION: As
gawk
version 5.1.0, this extension is considered to be obsolete.It is replaced by the
timex
extension ingawkextlib
(see section Thegawkextlib
Project).For version 5.1, no warning will be issued if this extension is used. For the next major release, a warning will be issued. In the release after that this extension will be removed from the distribution.
The time
extension adds two functions, named gettimeofday()
and sleep()
, as follows:
@load "time"
This is how you load the extension.
the_time = gettimeofday()
Return the time in seconds that has elapsed since 1970-01-01 UTC as a floating-point value. If the time is unavailable on this platform, return -1 and set
ERRNO
. The returned time should have sub-second precision, but the actual precision may vary based on the platform. If the standard Cgettimeofday()
system call is available on this platform, then it simply returns the value. Otherwise, if on MS-Windows, it tries to useGetSystemTimeAsFileTime()
.result = sleep(seconds)
Attempt to sleep for
seconds
seconds. Ifseconds
is negative, or the attempt to sleep fails, return -1 and setERRNO
. Otherwise, return zero after sleeping for the indicated amount of time. Note thatseconds
may be a floating-point (nonintegral) value. Implementation details: depending on platform availability, this function tries to usenanosleep()
orselect()
to implement the delay.