|
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | STANDARDS | HISTORY | SEE ALSO | COLOPHON |
|
|
|
timespec_get(3) Library Functions Manual timespec_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, 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
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) structure 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 retrieved by
clock_gettime(CLOCK_REALTIME, res) and
clock_getres(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 resolution in this time base are
the same as those retrieved by
clock_gettime(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_gettime(CLOCK_PROCESS_CPUTIME_ID, res) and
clock_getres(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_gettime(CLOCK_THREAD_CPUTIME_ID, res) and
clock_getres(CLOCK_THREAD_CPUTIME_ID, tp), respectively.
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.
For an explanation of the terms used in this section, see
attributes(7).
┌──────────────────────────────────────┬───────────────┬─────────┐
│ Interface │ Attribute │ Value │
├──────────────────────────────────────┼───────────────┼─────────┤
│ timespec_get(), timespec_getres() │ Thread safety │ MT-Safe │
└──────────────────────────────────────┴───────────────┴─────────┘
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.
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.
clock_gettime(2), clock_getres(2)
This page is part of the man-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.18.tar.gz
fetched from
⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
2026-05-24. 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 is not
part of the original manual page), send a mail to
man-pages@man7.org
Linux man-pages 6.18 2026-02-11 timespec_get(3)