clock_getres(2) System Calls Manual clock_getres(2) clock_getres, clock_gettime, clock_settime - C (libc, -lc) glibc 2.17 glibc 2.17 (librt -lrt) #include int clock_getres(clockid_t clockid, struct timespec *_Nullable res); int clock_gettime(clockid_t clockid, struct timespec *tp); int clock_settime(clockid_t clockid, const struct timespec *tp); glibc ( feature_test_macros(7)): clock_getres() clock_gettime() clock_settime(): _POSIX_C_SOURCE >= 199309L clock_getres() () clockid res NULL struct timespec res. . tp clock_settime() res res. clock_gettime() clock_settime() clockid . res tp timespec(3). clockid . . CLOCK_REALTIME. . . . . glibc : CLOCK_REALTIME ( ). . ( ) NTP adjtime(3) adjtimex(2) clock_adjtime(2) ntp_adjtime(3). 1970-01-01 00:00:00 (UTC) NTP UTC. CLOCK_REALTIME_ALARM ( 3.0 ) CLOCK_REALTIME CLOCK_REALTIME . timer_create(2). CLOCK_REALTIME_COARSE ( 2.6.32 ) CLOCK_REALTIME. CLOCK_REALTIME. . vdso(7). CLOCK_TAI ( 3.10 ) . CLOCK_REALTIME. 1970-01-01 00:00 TAI (1969-12-31 23:59:50 UTC) CLOCK_REALTIME . NTP CLOCK_REALTIME . CLOCK_REALTIME 1972 1972-01-01. 37 CLOCK_REALTIME CLOCK_REALTIME . CLOCK_REALTIME. TAI "temps atomique international" . CLOCK_MONOTONIC -- POSIX--" ". . CLOCK_MONOTONIC ( ) . . CLOCK_MONOTONIC -- -- ( ). CLOCK_MONOTONIC_COARSE ( 2.6.32 ) CLOCK_MONOTONIC. . vdso(7). CLOCK_MONOTONIC_RAW ( 2.6.28 ) CLOCK_MONOTONIC . . CLOCK_BOOTTIME ( 2.6.39 ) CLOCK_MONOTONIC . CLOCK_REALTIME settimeofday(2) . CLOCK_BOOTTIME_ALARM ( 3.0 ) CLOCK_BOOTTIME . timer_create(2). CLOCK_PROCESS_CPUTIME_ID ( 2.6.12) ( ). . CLOCK_THREAD_CPUTIME_ID ( 2.6.12) . . . System-V POSIX . "" 2.6.39. clock_gettime() clock_settime() clock_adjtime(2). . #define CLOCKFD 3 #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) #define CLOCKID_TO_FD(clk) ((unsigned int) ~((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); clock_gettime() clock_settime() clock_getres() 0 . -1 errno . EACCES clock_settime() POSIX . EFAULT tp . EINVAL clockid . System-V . EINVAL (clock_settime()): tp.tv_sec tp.tv_nsec [0, 999,999,999]. EINVAL clockid clock_settime() . EINVAL ( 4.3) clock_settime() clockid CLOCK_REALTIME CLOCK_MONOTONIC. ENODEV ( USB ) clk_id . ENOTSUP POSIX . EOVERFLOW time_t. time_t 32 64 2038-01-19 03:14:08 UTC . time_t . EPERM clock_settime() . attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |clock_getres(),| | MT-Safe | |clock_gettime(),| | | |clock_settime()| | | +------------+------------------------------------+--------------------+ POSIX.1 : CLOCK_REALTIME clock_settime() nanosleep() . . POSIX.1-2001 " " CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID clock_settime(). ( " "). C clock_gettime() vdso(7). POSIX.1-2024. POSIX.1-1996 2.6. POSIX _POSIX_TIMERS 0. POSIX.1-2008 . _POSIX_MONOTONIC_CLOCK _POSIX_CPUTIME _POSIX_THREAD_CPUTIME CLOCK_MONOTONIC CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID . ( sysconf(3).) POSIX.1-2024 CLOCK_MONOTONIC . SMP CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID glibc (TSC i386 AR.ITC Itanium). . SMP . clock_getcpuclockid(0) ENOENT . . SMP . . . glibc ( ). . glibc 2.4 CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID ( 2.6.12 ). clock_gettime() clock_getres() . : $ ./clock_times x; CLOCK_REALTIME : 1585985459.446 (18356 days + 7h 30m 59s) resolution: 0.000000001 CLOCK_TAI : 1585985496.447 (18356 days + 7h 31m 36s) resolution: 0.000000001 CLOCK_MONOTONIC: 52395.722 (14h 33m 15s) resolution: 0.000000001 CLOCK_BOOTTIME : 72691.019 (20h 11m 31s) resolution: 0.000000001 /* clock_times.c Licensed under GNU General Public License v2 or later. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #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(")\n"); if (clock_getres(clock, &ts) == -1) { perror("clock_getres"); exit(EXIT_FAILURE); } if (showRes) printf(" resolution: %10jd.%09ld\n", (intmax_t) ts.tv_sec, ts.tv_nsec); } int main(int argc, char *[]) { bool showRes = argc > 1; displayClock(CLOCK_REALTIME, "CLOCK_REALTIME", showRes); #ifdef CLOCK_TAI displayClock(CLOCK_TAI, "CLOCK_TAI", showRes); #endif displayClock(CLOCK_MONOTONIC, "CLOCK_MONOTONIC", showRes); #ifdef CLOCK_BOOTTIME displayClock(CLOCK_BOOTTIME, "CLOCK_BOOTTIME", showRes); #endif exit(EXIT_SUCCESS); } date(1), gettimeofday(2), settimeofday(2), time(2), adjtime(3), clock_getcpuclockid(3), ctime(3), ftime(3), pthread_getcpuclockid(3), sysconf(3), timespec(3), time(7), time_namespaces(7), vdso(7), hwclock(8) 3 . . : . 6.18 7 2026 clock_getres(2)