timespec_get(3) Library Functions Manual timespec_get(3) NAME timespec_get, timespec_getres - ISO C interface to clock and time functions LIBRARY Standard C library (libc, -lc) SYNOPSIS #include int timespec_get(struct timespec *res, int base); int timespec_getres(struct timespec *tp, int base); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): timespec_get(), TIME_UTC: _ISOC11_SOURCE timespec_getres(), TIME_MONOTONIC, TIME_ACTIVE, TIME_THREAD_ACTIVE: _ISOC23_SOURCE DESCRIPTION The timespec_get() function stores the current time, based on the specified time base, in the timespec(3type) structure pointed to by res. The timespec_getres() function stores the resolution of times retrieved by timespec_get() with the specified time base in the timespec(3type) struc- ture pointed to by tp, if tp is non-NULL. For a particular time base, the resolution is constant for the lifetime of the calling process. The time base base is one of the following: TIME_UTC A system-wide time base that measures real (i.e., wall-clock) time. The time and resolution in this time base are the same as those re- trieved by clock_gettime(CLOCK_REALTIME, res) and clock_ge- tres(CLOCK_REALTIME, tp), respectively. TIME_MONOTONIC A time base that measures time since an unspecified point in the past, where the time within a process will not decrease even if the system's real time clock is set or adjusted. The time and resolu- tion in this time base are the same as those retrieved by clock_get- time(CLOCK_MONOTONIC, res) and clock_getres(CLOCK_MONOTONIC, tp), respectively. TIME_ACTIVE A process-specific time base that measures CPU time consumed by the calling process. The time and resolution in this time base are the same as those retrieved by clock_get- time(CLOCK_PROCESS_CPUTIME_ID, res) and clock_ge- tres(CLOCK_PROCESS_CPUTIME_ID, tp), respectively. TIME_THREAD_ACTIVE A thread-specific time base that measures CPU time consumed by the calling thread. The time and resolution in this time base are the same as those retrieved by clock_get- time(CLOCK_THREAD_CPUTIME_ID, res) and clock_ge- tres(CLOCK_THREAD_CPUTIME_ID, tp), respectively. RETURN VALUE timespec_get() returns the nonzero base if it is a supported time base and the current time was successfully retrieved, or 0 otherwise. timespec_getres() returns the nonzero base if it is a supported time base, or 0 otherwise. ATTRIBUTES For an explanation of the terms used in this section, see attributes(7). allbox; lbx lb lb l l l. Interface Attribute Value T{ timespec_get(), timespec_getres() T} Thread safety MT-Safe STANDARDS timespec_get() C23, POSIX.1-2024. TIME_UTC C23 (though ISO C doesn't specify the time epoch), POSIX.1-2024. timespec_getres() TIME_MONOTONIC TIME_ACTIVE TIME_THREAD_ACTIVE C23. HISTORY timespec_get() TIME_UTC C11, POSIX.1-2024, glibc 2.16, musl 1.1.10. timespec_getres() C23, glibc 2.34. TIME_MONOTONIC TIME_ACTIVE TIME_THREAD_ACTIVE C23, glibc 2.43. SEE ALSO clock_gettime(2), clock_getres(2) Linux man-pages 6.18 2026-02-11 timespec_get(3)