'\" t .\" SPDX-License-Identifier: 0BSD .\" .TH timespec_get 3 2026-02-11 "Linux man-pages 6.19" .SH NAME timespec_get, timespec_getres \- ISO C interface to clock and time functions .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .B #include .P .BI "int timespec_get(struct timespec *" res ", int " base ); .BI "int timespec_getres(struct timespec *" tp ", int " base ); .fi .P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .P .BR timespec_get (), .BR TIME_UTC : .nf _ISOC11_SOURCE .fi .P .BR timespec_getres (), .BR TIME_MONOTONIC , .BR TIME_ACTIVE , .BR TIME_THREAD_ACTIVE : .nf _ISOC23_SOURCE .fi .SH DESCRIPTION The .BR timespec_get () function stores the current time, based on the specified time base, in the .BR timespec (3type) structure pointed to by .IR res . .P The .BR timespec_getres () function stores the resolution of times retrieved by .BR timespec_get () with the specified time base in the .BR timespec (3type) structure pointed to by .IR tp , if .I tp is non-NULL. For a particular time base, the resolution is constant for the lifetime of the calling process. .P The time base .I base is one of the following: .TP .B 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 .I clock_gettime(CLOCK_REALTIME,\~res) and .IR clock_getres(CLOCK_REALTIME,\~tp) , respectively. .TP .B 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 .I clock_gettime(CLOCK_MONOTONIC,\~res) and .IR clock_getres(CLOCK_MONOTONIC,\~tp) , respectively. .TP .B 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 .I clock_gettime(CLOCK_PROCESS_CPUTIME_ID,\~res) and .IR clock_getres(CLOCK_PROCESS_CPUTIME_ID,\~tp) , respectively. .TP .B 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 .I clock_gettime(CLOCK_THREAD_CPUTIME_ID,\~res) and .IR clock_getres(CLOCK_THREAD_CPUTIME_ID,\~tp) , respectively. .SH RETURN VALUE .BR timespec_get () returns the nonzero .I base if it is a supported time base and the current time was successfully retrieved, or 0 otherwise. .P .BR timespec_getres () returns the nonzero .I base if it is a supported time base, or 0 otherwise. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR timespec_get (), .BR timespec_getres () T} Thread safety MT-Safe .TE .SH STANDARDS .TP .BR timespec_get () C23, POSIX.1-2024. .TQ .B TIME_UTC C23 (though ISO C doesn't specify the time epoch), POSIX.1-2024. .TP .BR timespec_getres () .TQ .B TIME_MONOTONIC .TQ .B TIME_ACTIVE .TQ .B TIME_THREAD_ACTIVE C23. .SH HISTORY .TP .BR timespec_get () .TQ .B TIME_UTC C11, POSIX.1-2024, glibc 2.16, musl 1.1.10. .TP .BR timespec_getres () C23, glibc 2.34. .TP .B TIME_MONOTONIC .TQ .B TIME_ACTIVE .TQ .B TIME_THREAD_ACTIVE C23, glibc 2.43. .SH SEE ALSO .BR clock_gettime (2), .BR clock_getres (2)