diff options
Diffstat (limited to 'man2/clock_getres.2')
-rw-r--r-- | man2/clock_getres.2 | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/man2/clock_getres.2 b/man2/clock_getres.2 index 71f642fae..170215d17 100644 --- a/man2/clock_getres.2 +++ b/man2/clock_getres.2 @@ -9,7 +9,7 @@ .\" 2003-08-24 aeb, large parts rewritten .\" 2004-08-06 Christoph Lameter <clameter@sgi.com>, SMP note .\" -.TH clock_getres 2 2023-02-12 "Linux man-pages 6.03" +.TH clock_getres 2 2023-07-20 "Linux man-pages 6.05.01" .SH NAME clock_getres, clock_gettime, clock_settime \- clock and time functions .SH LIBRARY @@ -226,11 +226,11 @@ dynamic clock ID. #define CLOCKFD 3 #define FD_TO_CLOCKID(fd) ((\[ti](clockid_t) (fd) << 3) | CLOCKFD) #define CLOCKID_TO_FD(clk) ((unsigned int) \[ti]((clk) >> 3)) - +\& struct timespec ts; clockid_t clkid; int fd; - +\& fd = open("/dev/ptp0", O_RDWR); clkid = FD_TO_CLOCKID(fd); clock_gettime(clkid, &ts); @@ -307,45 +307,24 @@ specified. .B EPERM .BR clock_settime () does not have permission to set the clock indicated. -.SH VERSIONS -These system calls first appeared in Linux 2.6. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). -.ad l -.nh .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ +.na +.nh .BR clock_getres (), .BR clock_gettime (), .BR clock_settime () T} Thread safety MT-Safe .TE -.hy -.ad .sp 1 -.SH STANDARDS -POSIX.1-2001, POSIX.1-2008, SUSv2. -.PP -On POSIX systems on which these functions are available, the symbol -.B _POSIX_TIMERS -is defined in \fI<unistd.h>\fP to a value greater than 0. -The symbols -.BR _POSIX_MONOTONIC_CLOCK , -.BR _POSIX_CPUTIME , -.B _POSIX_THREAD_CPUTIME -indicate that -.BR CLOCK_MONOTONIC , -.BR CLOCK_PROCESS_CPUTIME_ID , -.B CLOCK_THREAD_CPUTIME_ID -are available. -(See also -.BR sysconf (3).) -.SH NOTES +.SH VERSIONS POSIX.1 specifies the following: .RS .PP @@ -370,12 +349,32 @@ clocks using On Linux, these clocks are not settable (i.e., no process has "appropriate privileges"). .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972 -.\" .SS C library/kernel differences On some architectures, an implementation of .BR clock_gettime () is provided in the .BR vdso (7). +.SH STANDARDS +POSIX.1-2008. +.SH HISTORY +POSIX.1-2001, SUSv2. +Linux 2.6. +.PP +On POSIX systems on which these functions are available, the symbol +.B _POSIX_TIMERS +is defined in \fI<unistd.h>\fP to a value greater than 0. +The symbols +.BR _POSIX_MONOTONIC_CLOCK , +.BR _POSIX_CPUTIME , +.B _POSIX_THREAD_CPUTIME +indicate that +.BR CLOCK_MONOTONIC , +.BR CLOCK_PROCESS_CPUTIME_ID , +.B CLOCK_THREAD_CPUTIME_ID +are available. +(See also +.BR sysconf (3).) +POSIX.1-2008 makes these APIs mandatory. .\" .SS Historical note for SMP systems Before Linux added kernel support for @@ -444,7 +443,7 @@ CLOCK_BOOTTIME : 72691.019 (20h 11m 31s) .\" SRC BEGIN (clock_getres.c) .EX /* clock_times.c - +\& Licensed under GNU General Public License v2 or later. */ #define _XOPEN_SOURCE 600 @@ -453,48 +452,48 @@ CLOCK_BOOTTIME : 72691.019 (20h 11m 31s) #include <stdio.h> #include <stdlib.h> #include <time.h> - +\& #define SECS_IN_DAY (24 * 60 * 60) - +\& static void displayClock(clockid_t clock, const char *name, bool showRes) { long days; struct timespec ts; - +\& if (clock_gettime(clock, &ts) == \-1) { perror("clock_gettime"); exit(EXIT_FAILURE); } - +\& printf("%\-15s: %10jd.%03ld (", name, (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); - +\& days = ts.tv_sec / SECS_IN_DAY; if (days > 0) printf("%ld days + ", days); - +\& printf("%2dh %2dm %2ds", (int) (ts.tv_sec % SECS_IN_DAY) / 3600, (int) (ts.tv_sec % 3600) / 60, (int) ts.tv_sec % 60); printf(")\en"); - +\& if (clock_getres(clock, &ts) == \-1) { perror("clock_getres"); exit(EXIT_FAILURE); } - +\& if (showRes) printf(" resolution: %10jd.%09ld\en", (intmax_t) ts.tv_sec, ts.tv_nsec); } - +\& int main(int argc, char *argv[]) { bool showRes = argc > 1; - +\& displayClock(CLOCK_REALTIME, "CLOCK_REALTIME", showRes); #ifdef CLOCK_TAI displayClock(CLOCK_TAI, "CLOCK_TAI", showRes); |