Debian Codegraph @

upstream/debian-unstable/man3/timespec_get.3

raw
1 '\" t
2 .\" SPDX-License-Identifier: 0BSD
3 .\"
4 .TH timespec_get 3 2026-02-11 "Linux man-pages 6.18"
5 .SH NAME
6 timespec_get,
7 timespec_getres
8 \-
9 ISO C interface to clock and time functions
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <time.h>
16 .P
17 .BI "int timespec_get(struct timespec *" res ", int " base );
18 .BI "int timespec_getres(struct timespec *" tp ", int " base );
19 .fi
20 .P
21 .RS -4
22 Feature Test Macro Requirements for glibc (see
23 .BR feature_test_macros (7)):
24 .RE
25 .P
26 .BR timespec_get (),
27 .BR TIME_UTC :
28 .nf
29 _ISOC11_SOURCE
30 .fi
31 .P
32 .BR timespec_getres (),
33 .BR TIME_MONOTONIC ,
34 .BR TIME_ACTIVE ,
35 .BR TIME_THREAD_ACTIVE :
36 .nf
37 _ISOC23_SOURCE
38 .fi
39 .SH DESCRIPTION
40 The
41 .BR timespec_get ()
42 function stores the current time, based on the specified time base, in the
43 .BR timespec (3type)
44 structure pointed to by
45 .IR res .
46 .P
47 The
48 .BR timespec_getres ()
49 function stores the resolution of times retrieved by
50 .BR timespec_get ()
51 with the specified time base in the
52 .BR timespec (3type)
53 structure pointed to by
54 .IR tp ,
55 if
56 .I tp
57 is non-NULL.
58 For a particular time base,
59 the resolution is constant for the lifetime of the calling process.
60 .P
61 The time base
62 .I base
63 is one of the following:
64 .TP
65 .B TIME_UTC
66 A system-wide time base that measures
67 real (i.e., wall-clock) time.
68 The time and resolution in this time base
69 are the same as those retrieved by
70 .I clock_gettime(CLOCK_REALTIME,\~res)
71 and
72 .IR clock_getres(CLOCK_REALTIME,\~tp) ,
73 respectively.
74 .TP
75 .B TIME_MONOTONIC
76 A time base that measures
77 time since an unspecified point in the past,
78 where the time within a process will not decrease
79 even if the system's real time clock is set or adjusted.
80 The time and resolution in this time base
81 are the same as those retrieved by
82 .I clock_gettime(CLOCK_MONOTONIC,\~res)
83 and
84 .IR clock_getres(CLOCK_MONOTONIC,\~tp) ,
85 respectively.
86 .TP
87 .B TIME_ACTIVE
88 A process-specific time base that measures
89 CPU time consumed by
90 the calling process.
91 The time and resolution in this time base
92 are the same as those retrieved by
93 .I clock_gettime(CLOCK_PROCESS_CPUTIME_ID,\~res)
94 and
95 .IR clock_getres(CLOCK_PROCESS_CPUTIME_ID,\~tp) ,
96 respectively.
97 .TP
98 .B TIME_THREAD_ACTIVE
99 A thread-specific time base that measures
100 CPU time consumed by
101 the calling thread.
102 The time and resolution in this time base
103 are the same as those retrieved by
104 .I clock_gettime(CLOCK_THREAD_CPUTIME_ID,\~res)
105 and
106 .IR clock_getres(CLOCK_THREAD_CPUTIME_ID,\~tp) ,
107 respectively.
108 .SH RETURN VALUE
109 .BR timespec_get ()
110 returns the nonzero
111 .I base
112 if it is a supported time base
113 and the current time was successfully retrieved, or 0 otherwise.
114 .P
115 .BR timespec_getres ()
116 returns the nonzero
117 .I base
118 if it is a supported time base, or 0 otherwise.
119 .SH ATTRIBUTES
120 For an explanation of the terms used in this section, see
121 .BR attributes (7).
122 .TS
123 allbox;
124 lbx lb lb
125 l l l.
126 Interface Attribute Value
127 T{
128 .na
129 .nh
130 .BR timespec_get (),
131 .BR timespec_getres ()
132 T} Thread safety MT-Safe
133 .TE
134 .SH STANDARDS
135 .TP
136 .BR timespec_get ()
137 C23, POSIX.1-2024.
138 .TQ
139 .B TIME_UTC
140 C23 (though ISO C doesn't specify the time epoch),
141 POSIX.1-2024.
142 .TP
143 .BR timespec_getres ()
144 .TQ
145 .B TIME_MONOTONIC
146 .TQ
147 .B TIME_ACTIVE
148 .TQ
149 .B TIME_THREAD_ACTIVE
150 C23.
151 .SH HISTORY
152 .TP
153 .BR timespec_get ()
154 .TQ
155 .B TIME_UTC
156 C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.
157 .TP
158 .BR timespec_getres ()
159 C23, glibc 2.34.
160 .TP
161 .B TIME_MONOTONIC
162 .TQ
163 .B TIME_ACTIVE
164 .TQ
165 .B TIME_THREAD_ACTIVE
166 C23, glibc 2.43.
167 .SH SEE ALSO
168 .BR clock_gettime (2),
169 .BR clock_getres (2)