www.LinuxHowtos.org
timespec_get
Section: C Library Functions (3)Updated: 202-0-11
Index Return to Main Contents
NAME
timespec_get, timespec_getres - ISO C interface to clock and time functionsLIBRARY
Standard C library (libc,~-lc)SYNOPSIS
#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
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) structure pointed to by tp, if tp is no-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 syste-wide time base that measures real (i.e., wal-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 proces-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 threa-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.
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).| Interface | Attribute | Value |
| timespec_get(), timespec_getres() | Thread safety | M-Safe |
STANDARDS
- timespec_get()
- C23, POSIX.-2024. TIME_UTC C23 (though ISO C doesn't specify the time epoch), POSIX.-2024.
- timespec_getres()
- TIME_MONOTONIC TIME_ACTIVE TIME_THREAD_ACTIVE C23.
HISTORY
- timespec_get()
- TIME_UTC C11, POSIX.-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)