NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ATTRIBUTES |STANDARDS |HISTORY |SEE ALSO |COLOPHON | |
timespec_get(3) Library Functions Manualtimespec_get(3)timespec_get, timespec_getres - ISO C interface to clock and time functions
Standard C library (libc,-lc),
#include <time.h>int timespec_get(struct timespec *res, intbase);int timespec_getres(struct timespec *tp, intbase);
Thetimespec_get() function stores the current time, based on the specified time base, in thetimespec(3type) structure pointed to byres. Thetimespec_getres() function stores the resolution of times retrieved bytimespec_get() with the specified time base in thetimespec(3type) structure pointed to bytp, iftp is non-NULL. For a particular time base, the resolution is constant for the lifetime of the calling process.TIME_UTCis always a supported time base, and is the only time base supported on Linux. The time and resolution in this time base are the same as those retrieved byclock_gettime(CLOCK_REALTIME, res) andclock_getres(CLOCK_REALTIME, tp), respectively. Other systems may support additional time bases.
timespec_get() returns the nonzerobase if it is a supported time base and the current time was successfully retrieved, or 0 otherwise.timespec_getres() returns the nonzerobase if it is a supported time base, or 0 otherwise.
For an explanation of the terms used in this section, seeattributes(7). ┌──────────────────────────────────────┬───────────────┬─────────┐ │Interface│Attribute│Value│ ├──────────────────────────────────────┼───────────────┼─────────┤ │timespec_get(),timespec_getres() │ Thread safety │ MT-Safe │ └──────────────────────────────────────┴───────────────┴─────────┘
timespec_get()TIME_UTC C23 (though ISO C doesn't specify the time epoch), POSIX.1-2024.timespec_getres() C23.
timespec_get()TIME_UTC C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.timespec_getres() C23, glibc 2.34.
clock_gettime(2),clock_getres(2)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.16.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2026-01-16. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.16 2025-02-10timespec_get(3)HTML rendering created 2026-01-16 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |