]>
Commit | Line | Data |
---|---|---|
02afffe0 MK |
1 | .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk |
2 | .\" <mtk.manpages@gmail.com> | |
3 | .\" | |
4 | .\" Permission is granted to make and distribute verbatim copies of this | |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
12 | .\" | |
13 | .\" Since the Linux kernel and libraries are constantly changing, this | |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
20 | .\" | |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
23 | .\" | |
0d3bd760 | 24 | .TH CLOCK_NANOSLEEP 2 2012-11-07 "Linux" "Linux Programmer's Manual" |
02afffe0 MK |
25 | .SH NAME |
26 | clock_nanosleep \- high-resolution sleep with specifiable clock | |
27 | .SH SYNOPSIS | |
28 | .B #include <time.h> | |
29 | .nf | |
30 | .sp | |
31 | .BI "int clock_nanosleep(clockid_t " clock_id ", int " flags , | |
32 | .BI " const struct timespec *" request , | |
33 | .BI " struct timespec *" remain ); | |
34 | .fi | |
35 | .sp | |
02959991 | 36 | Link with \fI\-lrt\fP (only for glibc versions before 2.17). |
4aeb366b | 37 | .sp |
9a30939e | 38 | .ad l |
02afffe0 MK |
39 | .in -4n |
40 | Feature Test Macro Requirements for glibc (see | |
41 | .BR feature_test_macros (7)): | |
42 | .in | |
43 | .sp | |
44 | .BR clock_nanosleep (): | |
9a30939e MK |
45 | .RS 4 |
46 | _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L | |
47 | .RE | |
48 | .ad | |
02afffe0 MK |
49 | .SH DESCRIPTION |
50 | Like | |
51 | .BR nanosleep (2), | |
52 | .BR clock_nanosleep () | |
2b1c23bd | 53 | allows the calling thread to sleep for an interval specified |
02afffe0 MK |
54 | with nanosecond precision. |
55 | It differs in allowing the caller to select the clock against | |
56 | which the sleep interval is to be measured, | |
57 | and in allowing the sleep interval to be specified as | |
58 | either an absolute or a relative value. | |
59 | ||
60 | The time values passed to and returned by this call are specified using | |
61 | .I timespec | |
62 | structures, defined as follows: | |
63 | .sp | |
64 | .in +4n | |
65 | .nf | |
66 | struct timespec { | |
67 | time_t tv_sec; /* seconds */ | |
68 | long tv_nsec; /* nanoseconds [0 .. 999999999] */ | |
69 | }; | |
70 | .fi | |
71 | .in | |
72 | ||
73 | The | |
74 | .I clock_id | |
75 | argument specifies the clock against which the sleep interval | |
76 | is to be measured. | |
77 | This argument can have one of the following values: | |
78 | .TP 17 | |
79 | .BR CLOCK_REALTIME | |
80 | A settable system-wide real-time clock. | |
81 | .TP | |
82 | .BR CLOCK_MONOTONIC | |
24b74457 | 83 | A nonsettable, monotonically increasing clock that measures time |
02afffe0 MK |
84 | since some unspecified point in the past that does not change after |
85 | system startup. | |
86 | .\" On Linux this clock measures time since boot. | |
87 | .TP | |
88 | .BR CLOCK_PROCESS_CPUTIME_ID | |
89 | A settable per-process clock that measures CPU time consumed | |
90 | by all threads in the process. | |
91 | .\" There is some trickery between glibc and the kernel | |
92 | .\" to deal with the CLOCK_PROCESS_CPUTIME_ID case. | |
93 | .PP | |
94 | See | |
0eb44391 | 95 | .BR clock_getres (2) |
02afffe0 MK |
96 | for further details on these clocks. |
97 | ||
98 | If | |
99 | .I flags | |
100 | is 0, then the value specified in | |
101 | .I request | |
102 | is interpreted as an interval relative to the current | |
103 | value of the clock specified by | |
104 | .IR clock_id . | |
105 | ||
106 | If | |
107 | .I flags | |
108 | is | |
109 | .BR TIMER_ABSTIME , | |
110 | then | |
111 | .I request | |
112 | is interpreted as an absolute time as measured by the clock, | |
113 | .IR clock_id . | |
114 | If | |
115 | .I request | |
116 | is less than or equal to the current value of the clock, | |
117 | then | |
118 | .BR clock_nanosleep () | |
119 | returns immediately without suspending the calling thread. | |
120 | ||
121 | .BR clock_nanosleep () | |
122 | suspends the execution of the calling thread | |
123 | until either at least the time specified by | |
124 | .IR request | |
125 | has elapsed, | |
126 | or a signal is delivered that causes a signal handler to be called or | |
127 | that terminates the process. | |
128 | ||
129 | If the call is interrupted by a signal handler, | |
130 | .BR clock_nanosleep () | |
81a0028c | 131 | fails with the error |
02afffe0 MK |
132 | .BR EINTR . |
133 | In addition, if | |
134 | .I remain | |
135 | is not NULL, and | |
136 | .I flags | |
137 | was not | |
138 | .BR TIMER_ABSTIME , | |
139 | it returns the remaining unslept time in | |
140 | .IR remain . | |
141 | This value can then be used to call | |
142 | .BR clock_nanosleep () | |
143 | again and complete a (relative) sleep. | |
47297adb | 144 | .SH RETURN VALUE |
02afffe0 MK |
145 | On successfully sleeping for the requested interval, |
146 | .BR clock_nanosleep () | |
147 | returns 0. | |
148 | If the call is interrupted by a signal handler or encounters an error, | |
535f0df5 | 149 | then it returns one of the positive error number listed in ERRORS. |
02afffe0 | 150 | .SH ERRORS |