]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da MK |
2 | .\" Copyright (c) 2003 Nick Clifford (zaf@nrc.co.nz), Jan 25, 2003 |
3 | .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl), Aug 24, 2003 | |
16fa5781 | 4 | .\" Copyright (c) 2020 Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 5 | .\" |
5fbde956 | 6 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
7 | .\" |
8 | .\" 2003-08-23 Martin Schulze <joey@infodrom.org> improvements | |
9 | .\" 2003-08-24 aeb, large parts rewritten | |
10 | .\" 2004-08-06 Christoph Lameter <clameter@sgi.com>, SMP note | |
11 | .\" | |
4c1c5274 | 12 | .TH clock_getres 2 (date) "Linux man-pages (unreleased)" |
fea681da MK |
13 | .SH NAME |
14 | clock_getres, clock_gettime, clock_settime \- clock and time functions | |
430fb656 AC |
15 | .SH LIBRARY |
16 | Standard C library | |
8fc3b2cf | 17 | .RI ( libc ", " \-lc ), |
430fb656 AC |
18 | since glibc 2.17 |
19 | .PP | |
20 | Before glibc 2.17, | |
21 | Real-time library | |
8fc3b2cf | 22 | .RI ( librt ", " \-lrt ) |
fea681da | 23 | .SH SYNOPSIS |
15d65653 | 24 | .nf |
fea681da | 25 | .B #include <time.h> |
68e4db0a | 26 | .PP |
d1c67288 | 27 | .BI "int clock_getres(clockid_t " clockid ", struct timespec *_Nullable " res ); |
dbfe9c70 | 28 | .PP |
ba1c6b20 | 29 | .BI "int clock_gettime(clockid_t " clockid ", struct timespec *" tp ); |
ba1c6b20 | 30 | .BI "int clock_settime(clockid_t " clockid ", const struct timespec *" tp ); |
15d65653 | 31 | .fi |
68e4db0a | 32 | .PP |
d39ad78f | 33 | .RS -4 |
cc4615cc MK |
34 | Feature Test Macro Requirements for glibc (see |
35 | .BR feature_test_macros (7)): | |
d39ad78f | 36 | .RE |
68e4db0a | 37 | .PP |
cc4615cc MK |
38 | .BR clock_getres (), |
39 | .BR clock_gettime (), | |
40 | .BR clock_settime (): | |
9d2adbae | 41 | .nf |
5c10d2c5 | 42 | _POSIX_C_SOURCE >= 199309L |
9d2adbae | 43 | .fi |
fea681da MK |
44 | .SH DESCRIPTION |
45 | The function | |
46 | .BR clock_getres () | |
47 | finds the resolution (precision) of the specified clock | |
ba1c6b20 | 48 | .IR clockid , |
fea681da MK |
49 | and, if |
50 | .I res | |
0c2ec4f1 | 51 | is non-NULL, stores it in the \fIstruct timespec\fP pointed to by |
fea681da MK |
52 | .IR res . |
53 | The resolution of clocks depends on the implementation and cannot be | |
54 | configured by a particular process. | |
55 | If the time value pointed to by the argument | |
56 | .I tp | |
57 | of | |
58 | .BR clock_settime () | |
59 | is not a multiple of | |
60 | .IR res , | |
61 | then it is truncated to a multiple of | |
62 | .IR res . | |
63 | .PP | |
64 | The functions | |
65 | .BR clock_gettime () | |
66 | and | |
67 | .BR clock_settime () | |
68 | retrieve and set the time of the specified clock | |
ba1c6b20 | 69 | .IR clockid . |
fea681da MK |
70 | .PP |
71 | The | |
72 | .I res | |
73 | and | |
74 | .I tp | |
75 | arguments are | |
e97e048a | 76 | .BR timespec (3) |
77 | structures. | |
fea681da | 78 | .PP |
c13182ef | 79 | The |
ba1c6b20 | 80 | .I clockid |
fea681da MK |
81 | argument is the identifier of the particular clock on which to act. |
82 | A clock may be system-wide and hence visible for all processes, or | |
83 | per-process if it measures time only within a single process. | |
dd3568a1 | 84 | .PP |
6f36deb4 | 85 | All implementations support the system-wide real-time clock, |
fea681da MK |
86 | which is identified by |
87 | .BR CLOCK_REALTIME . | |
88 | Its time represents seconds and nanoseconds since the Epoch. | |
89 | When its time is changed, timers for a relative interval are | |
90 | unaffected, but timers for an absolute point in time are affected. | |
dd3568a1 | 91 | .PP |
c13182ef MK |
92 | More clocks may be implemented. |
93 | The interpretation of the | |
fea681da | 94 | corresponding time values and the effect on timers is unspecified. |
dd3568a1 | 95 | .PP |
5260fe08 | 96 | Sufficiently recent versions of glibc and the Linux kernel |
fea681da MK |
97 | support the following clocks: |
98 | .TP | |
99 | .B CLOCK_REALTIME | |
41043c0b | 100 | A settable system-wide clock that measures real (i.e., wall-clock) time. |
fea681da | 101 | Setting this clock requires appropriate privileges. |
22594a3c MK |
102 | This clock is affected by discontinuous jumps in the system time |
103 | (e.g., if the system administrator manually changes the clock), | |
104 | and by the incremental adjustments performed by | |
65a0c012 | 105 | .BR adjtime (3) |
22594a3c | 106 | and NTP. |
f5546fcd | 107 | .TP |
eb6567fb MK |
108 | .BR CLOCK_REALTIME_ALARM " (since Linux 3.0; Linux-specific)" |
109 | Like | |
110 | .BR CLOCK_REALTIME , | |
111 | but not settable. | |
112 | See | |
113 | .BR timer_create (2) | |
114 | for further details. | |
115 | .TP | |
55f749ae CH |
116 | .BR CLOCK_REALTIME_COARSE " (since Linux 2.6.32; Linux-specific)" |
117 | .\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3 | |
1d33f7d7 MK |
118 | A faster but less precise version of |
119 | .BR CLOCK_REALTIME . | |
14df252b | 120 | This clock is not settable. |
55f749ae | 121 | Use when you need very fast, but not fine-grained timestamps. |
c74bc519 MK |
122 | Requires per-architecture support, |
123 | and probably also architecture support for this flag in the | |
124 | .BR vdso (7). | |
55f749ae | 125 | .TP |
3eee7515 | 126 | .BR CLOCK_TAI " (since Linux 3.10; Linux-specific)" |
da9fe87d | 127 | .\" commit 1ff3c9677bff7e468e0c487d0ffefe4e901d33f4 |
9d69bebb MK |
128 | A nonsettable system-wide clock derived from wall-clock time |
129 | but ignoring leap seconds. | |
da9fe87d MK |
130 | This clock does |
131 | not experience discontinuities and backwards jumps caused by NTP | |
132 | inserting leap seconds as | |
1ae6b2c7 | 133 | .B CLOCK_REALTIME |
3eee7515 BP |
134 | does. |
135 | .IP | |
136 | The acronym TAI refers to International Atomic Time. | |
137 | .TP | |
fea681da | 138 | .B CLOCK_MONOTONIC |
a04e44bd MK |
139 | A nonsettable system-wide clock that |
140 | represents monotonic time since\(emas described | |
7d882a4a MK |
141 | by POSIX\(em"some unspecified point in the past". |
142 | On Linux, that point corresponds to the number of seconds that the system | |
143 | has been running since it was booted. | |
144 | .IP | |
145 | The | |
146 | .B CLOCK_MONOTONIC | |
147 | clock is not affected by discontinuous jumps in the system time | |
63f0f3d9 MK |
148 | (e.g., if the system administrator manually changes the clock), |
149 | but is affected by the incremental adjustments performed by | |
65a0c012 | 150 | .BR adjtime (3) |
63f0f3d9 | 151 | and NTP. |
f224d2bc | 152 | This clock does not count time that the system is suspended. |
7b02075b HD |
153 | All |
154 | .B CLOCK_MONOTONIC | |
155 | variants guarantee that the time returned by consecutive calls will not go | |
7b9f3195 MK |
156 | backwards, but successive calls may\(emdepending on the architecture\(emreturn |
157 | identical (not-increased) time values. | |
f5546fcd | 158 | .TP |
55f749ae CH |
159 | .BR CLOCK_MONOTONIC_COARSE " (since Linux 2.6.32; Linux-specific)" |
160 | .\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3 | |
1d33f7d7 MK |
161 | A faster but less precise version of |
162 | .BR CLOCK_MONOTONIC . | |
55f749ae | 163 | Use when you need very fast, but not fine-grained timestamps. |
c74bc519 MK |
164 | Requires per-architecture support, |
165 | and probably also architecture support for this flag in the | |
166 | .BR vdso (7). | |
fea681da | 167 | .TP |
1ba3fba8 MK |
168 | .BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)" |
169 | .\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz | |
170 | Similar to | |
171 | .BR CLOCK_MONOTONIC , | |
172 | but provides access to a raw hardware-based time | |
63f0f3d9 MK |
173 | that is not subject to NTP adjustments or |
174 | the incremental adjustments performed by | |
65a0c012 | 175 | .BR adjtime (3). |
4eae8eb7 | 176 | This clock does not count time that the system is suspended. |
1ba3fba8 | 177 | .TP |
b28712e1 | 178 | .BR CLOCK_BOOTTIME " (since Linux 2.6.39; Linux-specific)" |
a5d9ce65 MK |
179 | .\" commit 7fdd7f89006dd5a4c702fa0ce0c272345fa44ae0 |
180 | .\" commit 70a08cca1227dc31c784ec930099a4417a06e7d0 | |
65ff4e23 | 181 | A nonsettable system-wide clock that is identical to |
b28712e1 | 182 | .BR CLOCK_MONOTONIC , |
2c16f1bc | 183 | except that it also includes any time that the system is suspended. |
a5d9ce65 MK |
184 | This allows applications to get a suspend-aware monotonic clock |
185 | without having to deal with the complications of | |
186 | .BR CLOCK_REALTIME , | |
187 | which may have discontinuities if the time is changed using | |
0bbe872f MK |
188 | .BR settimeofday (2) |
189 | or similar. | |
b28712e1 | 190 | .TP |
eb6567fb MK |
191 | .BR CLOCK_BOOTTIME_ALARM " (since Linux 3.0; Linux-specific)" |
192 | Like | |
193 | .BR CLOCK_BOOTTIME . | |
194 | See | |
195 | .BR timer_create (2) | |
196 | for further details. | |
197 | .TP | |
783d6cb4 | 198 | .BR CLOCK_PROCESS_CPUTIME_ID " (since Linux 2.6.12)" |
ac90b589 | 199 | This is a clock that measures CPU time consumed by this process |
c009a15c | 200 | (i.e., CPU time consumed by all threads in the process). |
71b7e2a5 | 201 | On Linux, this clock is not settable. |
fea681da | 202 | .TP |
783d6cb4 | 203 | .BR CLOCK_THREAD_CPUTIME_ID " (since Linux 2.6.12)" |
ac90b589 | 204 | This is a clock that measures CPU time consumed by this thread. |
71b7e2a5 | 205 | On Linux, this clock is not settable. |
f377393e RC |
206 | .PP |
207 | Linux also implements dynamic clock instances as described below. | |
bd72f280 MK |
208 | .SS Dynamic clocks |
209 | In addition to the hard-coded System-V style clock IDs described above, | |
210 | Linux also supports | |
aab94212 MK |
211 | POSIX clock operations on certain character devices. |
212 | Such devices are | |
bd72f280 MK |
213 | called "dynamic" clocks, and are supported since Linux 2.6.39. |
214 | .PP | |
aab94212 | 215 | Using the appropriate macros, open file |
bd72f280 | 216 | descriptors may be converted into clock IDs and passed to |
f377393e RC |
217 | .BR clock_gettime (), |
218 | .BR clock_settime (), | |
219 | and | |
bd72f280 MK |
220 | .BR clock_adjtime (2). |
221 | The following example shows how to convert a file descriptor into a | |
222 | dynamic clock ID. | |
f377393e RC |
223 | .PP |
224 | .in +4n | |
225 | .EX | |
226 | #define CLOCKFD 3 | |
af2d18b2 MK |
227 | #define FD_TO_CLOCKID(fd) ((\(ti(clockid_t) (fd) << 3) | CLOCKFD) |
228 | #define CLOCKID_TO_FD(clk) ((unsigned int) \(ti((clk) >> 3)) | |
f377393e | 229 | |
fb84ed2a | 230 | struct timespec ts; |
f377393e RC |
231 | clockid_t clkid; |
232 | int fd; | |
233 | ||
234 | fd = open("/dev/ptp0", O_RDWR); | |
235 | clkid = FD_TO_CLOCKID(fd); | |
fb84ed2a | 236 | clock_gettime(clkid, &ts); |
f377393e RC |
237 | .EE |
238 | .in | |
47297adb | 239 | .SH RETURN VALUE |
e1d6264d | 240 | .BR clock_gettime (), |
cc83f4d1 | 241 | .BR clock_settime (), |
fea681da MK |
242 | and |
243 | .BR clock_getres () | |
c112329f MK |
244 | return 0 for success. |
245 | On error, \-1 is returned and | |
fea681da | 246 | .I errno |
c112329f | 247 | is set to indicate the error. |
fea681da MK |
248 | .SH ERRORS |
249 | .TP | |
19b2538d MK |
250 | .B EACCES |
251 | .BR clock_settime () | |
252 | does not have write permission for the dynamic POSIX | |
253 | clock device indicated. | |
254 | .TP | |
fea681da MK |
255 | .B EFAULT |
256 | .I tp | |
257 | points outside the accessible address space. | |
258 | .TP | |
259 | .B EINVAL | |
c13182ef | 260 | The |
ba1c6b20 | 261 | .I clockid |
aab94212 | 262 | specified is invalid for one of two reasons. |
bd72f280 MK |
263 | Either the System-V style |
264 | hard coded positive value is out of range, or the dynamic clock ID | |
f377393e | 265 | does not refer to a valid instance of a clock object. |
a113440c MK |
266 | .\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID |
267 | .\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be | |
268 | .\" EPERM. | |
fea681da | 269 | .TP |
9f23d947 MK |
270 | .B EINVAL |
271 | .RB ( clock_settime ()): | |
272 | .I tp.tv_sec | |
273 | is negative or | |
9a82d4d9 | 274 | .I tp.tv_nsec |
9f23d947 MK |
275 | is outside the range [0..999,999,999]. |
276 | .TP | |
238442a2 MK |
277 | .B EINVAL |
278 | The | |
ba1c6b20 | 279 | .I clockid |
238442a2 MK |
280 | specified in a call to |
281 | .BR clock_settime () | |
282 | is not a settable clock. | |
283 | .TP | |
bccacb94 MK |
284 | .BR EINVAL " (since Linux 4.3)" |
285 | .\" commit e1d7ba8735551ed79c7a0463a042353574b96da3 | |
286 | A call to | |
287 | .BR clock_settime () | |
288 | with a | |
ba1c6b20 | 289 | .I clockid |
bccacb94 MK |
290 | of |
291 | .B CLOCK_REALTIME | |
292 | attempted to set the time to a value less than | |
293 | the current value of the | |
294 | .B CLOCK_MONOTONIC | |
295 | clock. | |
296 | .TP | |
f377393e | 297 | .B ENODEV |
bd72f280 | 298 | The hot-pluggable device (like USB for example) represented by a |
f377393e RC |
299 | dynamic |
300 | .I clk_id | |
301 | has disappeared after its character device was opened. | |
302 | .TP | |
19b2538d MK |
303 | .B ENOTSUP |
304 | The operation is not supported by the dynamic POSIX clock device | |
305 | specified. | |
306 | .TP | |
fea681da MK |
307 | .B EPERM |
308 | .BR clock_settime () | |
309 | does not have permission to set the clock indicated. | |
e272bb60 | 310 | .SH VERSIONS |
50b25c38 | 311 | These system calls first appeared in Linux 2.6. |
546e17ce ZL |
312 | .SH ATTRIBUTES |
313 | For an explanation of the terms used in this section, see | |
314 | .BR attributes (7). | |
c466875e MK |
315 | .ad l |
316 | .nh | |
546e17ce ZL |
317 | .TS |
318 | allbox; | |
c466875e | 319 | lbx lb lb |
546e17ce ZL |
320 | l l l. |
321 | Interface Attribute Value | |
322 | T{ | |
323 | .BR clock_getres (), | |
324 | .BR clock_gettime (), | |
325 | .BR clock_settime () | |
326 | T} Thread safety MT-Safe | |
327 | .TE | |
c466875e MK |
328 | .hy |
329 | .ad | |
efeece04 | 330 | .sp 1 |
3113c7f3 | 331 | .SH STANDARDS |
75ee6a07 | 332 | POSIX.1-2001, POSIX.1-2008, SUSv2. |
bd168648 | 333 | .PP |
2b2581ee MK |
334 | On POSIX systems on which these functions are available, the symbol |
335 | .B _POSIX_TIMERS | |
c84371c6 | 336 | is defined in \fI<unistd.h>\fP to a value greater than 0. |
2b2581ee MK |
337 | The symbols |
338 | .BR _POSIX_MONOTONIC_CLOCK , | |
339 | .BR _POSIX_CPUTIME , | |
340 | .B _POSIX_THREAD_CPUTIME | |
341 | indicate that | |
342 | .BR CLOCK_MONOTONIC , | |
343 | .BR CLOCK_PROCESS_CPUTIME_ID , | |
344 | .B CLOCK_THREAD_CPUTIME_ID | |
345 | are available. | |
346 | (See also | |
347 | .BR sysconf (3).) | |
19c98696 | 348 | .SH NOTES |
f086b6aa MK |
349 | POSIX.1 specifies the following: |
350 | .RS | |
351 | .PP | |
352 | Setting the value of the | |
353 | .B CLOCK_REALTIME | |
354 | clock via | |
e470433f | 355 | .BR clock_settime () |
f086b6aa MK |
356 | shall have no effect on threads that are blocked waiting for a relative time |
357 | service based upon this clock, including the | |
358 | .BR nanosleep () | |
359 | function; nor on the expiration of relative timers based upon this clock. | |
360 | Consequently, these time services shall expire when the requested relative | |
361 | interval elapses, independently of the new or old value of the clock. | |
a3847715 | 362 | .RE |
a2150697 MK |
363 | .PP |
364 | According to POSIX.1-2001, a process with "appropriate privileges" may set the | |
365 | .B CLOCK_PROCESS_CPUTIME_ID | |
366 | and | |
367 | .B CLOCK_THREAD_CPUTIME_ID | |
368 | clocks using | |
369 | .BR clock_settime (). | |
370 | On Linux, these clocks are not settable | |
371 | (i.e., no process has "appropriate privileges"). | |
372 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972 | |
f086b6aa | 373 | .\" |
f8c419a4 MK |
374 | .SS C library/kernel differences |
375 | On some architectures, an implementation of | |
376 | .BR clock_gettime () | |
377 | is provided in the | |
378 | .BR vdso (7). | |
379 | .\" | |
78638aae MK |
380 | .SS Historical note for SMP systems |
381 | Before Linux added kernel support for | |
fea681da MK |
382 | .B CLOCK_PROCESS_CPUTIME_ID |
383 | and | |
78638aae MK |
384 | .BR CLOCK_THREAD_CPUTIME_ID , |
385 | glibc implemented these clocks on many platforms using timer | |
386 | registers from the CPUs | |
fea681da MK |
387 | (TSC on i386, AR.ITC on Itanium). |
388 | These registers may differ between CPUs and as a consequence | |
389 | these clocks may return | |
390 | .B bogus results | |
391 | if a process is migrated to another CPU. | |
392 | .PP | |
f14ae16e | 393 | If the CPUs in an SMP system have different clock sources, then |
fea681da | 394 | there is no way to maintain a correlation between the timer registers since |
c13182ef | 395 | each CPU will run at a slightly different frequency. |
f14ae16e | 396 | If that is the case, then |
fea681da MK |
397 | .I clock_getcpuclockid(0) |
398 | will return | |
399 | .B ENOENT | |
c13182ef | 400 | to signify this condition. |
33a0ccb2 | 401 | The two clocks will then be useful only if it |
fea681da MK |
402 | can be ensured that a process stays on a certain CPU. |
403 | .PP | |
404 | The processors in an SMP system do not start all at exactly the same | |
405 | time and therefore the timer registers are typically running at an offset. | |
406 | Some architectures include code that attempts to limit these offsets on bootup. | |
407 | However, the code cannot guarantee to accurately tune the offsets. | |
408 | Glibc contains no provisions to deal with these offsets (unlike the Linux | |
c13182ef MK |
409 | Kernel). |
410 | Typically these offsets are small and therefore the effects may be | |
fea681da | 411 | negligible in most cases. |
efeece04 | 412 | .PP |
78638aae MK |
413 | Since glibc 2.4, |
414 | the wrapper functions for the system calls described in this page avoid | |
415 | the abovementioned problems by employing the kernel implementation of | |
416 | .B CLOCK_PROCESS_CPUTIME_ID | |
417 | and | |
418 | .BR CLOCK_THREAD_CPUTIME_ID , | |
419 | on systems that provide such an implementation | |
420 | (i.e., Linux 2.6.12 and later). | |
a14af333 | 421 | .SH EXAMPLES |
16fa5781 MK |
422 | The program below demonstrates the use of |
423 | .BR clock_gettime () | |
424 | and | |
425 | .BR clock_getres () | |
426 | with various clocks. | |
427 | This is an example of what we might see when running the program: | |
428 | .PP | |
429 | .in +4n | |
430 | .EX | |
431 | $ \fB./clock_times x\fP | |
bef940ca MK |
432 | CLOCK_REALTIME : 1585985459.446 (18356 days + 7h 30m 59s) |
433 | resolution: 0.000000001 | |
434 | CLOCK_TAI : 1585985496.447 (18356 days + 7h 31m 36s) | |
435 | resolution: 0.000000001 | |
436 | CLOCK_MONOTONIC: 52395.722 (14h 33m 15s) | |
437 | resolution: 0.000000001 | |
438 | CLOCK_BOOTTIME : 72691.019 (20h 11m 31s) | |
439 | resolution: 0.000000001 | |
16fa5781 MK |
440 | .EE |
441 | .in | |
442 | .SS Program source | |
443 | \& | |
33857069 | 444 | .\" SRC BEGIN (clock_getres.c) |
16fa5781 MK |
445 | .EX |
446 | /* clock_times.c | |
447 | ||
448 | Licensed under GNU General Public License v2 or later. | |
449 | */ | |
450 | #define _XOPEN_SOURCE 600 | |
47b94bbd | 451 | #include <stdbool.h> |
8eb90116 | 452 | #include <stdint.h> |
16fa5781 MK |
453 | #include <stdio.h> |
454 | #include <stdlib.h> | |
47b94bbd | 455 | #include <time.h> |
16fa5781 MK |
456 | |
457 | #define SECS_IN_DAY (24 * 60 * 60) | |
458 | ||
459 | static void | |
276dc9a3 | 460 | displayClock(clockid_t clock, const char *name, bool showRes) |
16fa5781 | 461 | { |
041a155c AC |
462 | long days; |
463 | struct timespec ts; | |
16fa5781 MK |
464 | |
465 | if (clock_gettime(clock, &ts) == \-1) { | |
466 | perror("clock_gettime"); | |
467 | exit(EXIT_FAILURE); | |
468 | } | |
469 | ||
8eb90116 | 470 | printf("%\-15s: %10jd.%03ld (", name, |
4687ab0e | 471 | (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); |
16fa5781 | 472 | |
041a155c | 473 | days = ts.tv_sec / SECS_IN_DAY; |
16fa5781 MK |
474 | if (days > 0) |
475 | printf("%ld days + ", days); | |
476 | ||
6fd153d5 | 477 | printf("%2dh %2dm %2ds", |
4687ab0e AC |
478 | (int) (ts.tv_sec % SECS_IN_DAY) / 3600, |
479 | (int) (ts.tv_sec % 3600) / 60, | |
480 | (int) ts.tv_sec % 60); | |
16fa5781 MK |
481 | printf(")\en"); |
482 | ||
483 | if (clock_getres(clock, &ts) == \-1) { | |
484 | perror("clock_getres"); | |
485 | exit(EXIT_FAILURE); | |
486 | } | |
487 | ||
488 | if (showRes) | |
8eb90116 | 489 | printf(" resolution: %10jd.%09ld\en", |
4687ab0e | 490 | (intmax_t) ts.tv_sec, ts.tv_nsec); |
16fa5781 MK |
491 | } |
492 | ||
493 | int | |
494 | main(int argc, char *argv[]) | |
495 | { | |
496 | bool showRes = argc > 1; | |
497 | ||
498 | displayClock(CLOCK_REALTIME, "CLOCK_REALTIME", showRes); | |
499 | #ifdef CLOCK_TAI | |
500 | displayClock(CLOCK_TAI, "CLOCK_TAI", showRes); | |
501 | #endif | |
502 | displayClock(CLOCK_MONOTONIC, "CLOCK_MONOTONIC", showRes); | |
503 | #ifdef CLOCK_BOOTTIME | |
504 | displayClock(CLOCK_BOOTTIME, "CLOCK_BOOTTIME", showRes); | |
505 | #endif | |
506 | exit(EXIT_SUCCESS); | |
507 | } | |
508 | .EE | |
33857069 | 509 | .\" SRC END |
47297adb | 510 | .SH SEE ALSO |
fea681da | 511 | .BR date (1), |
fea681da MK |
512 | .BR gettimeofday (2), |
513 | .BR settimeofday (2), | |
514 | .BR time (2), | |
65a0c012 | 515 | .BR adjtime (3), |
edf60acb | 516 | .BR clock_getcpuclockid (3), |
fea681da MK |
517 | .BR ctime (3), |
518 | .BR ftime (3), | |
24ad017d | 519 | .BR pthread_getcpuclockid (3), |
1d7c4d16 | 520 | .BR sysconf (3), |
e97e048a | 521 | .BR timespec (3), |
18688d17 | 522 | .BR time (7), |
68220f1c | 523 | .BR time_namespaces (7), |
1ce611a3 MK |
524 | .BR vdso (7), |
525 | .BR hwclock (8) |