]>
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 | .\" | |
4aeb366b | 24 | .TH CLOCK_NANOSLEEP 2 2008-07-09 "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 | |
4aeb366b MK |
36 | Link with \fI\-lrt\fP. |
37 | .sp | |
02afffe0 MK |
38 | .in -4n |
39 | Feature Test Macro Requirements for glibc (see | |
40 | .BR feature_test_macros (7)): | |
41 | .in | |
42 | .sp | |
43 | .BR clock_nanosleep (): | |
44 | _XOPEN_SOURCE\ >=\ 600 | |
45 | .SH DESCRIPTION | |
46 | Like | |
47 | .BR nanosleep (2), | |
48 | .BR clock_nanosleep () | |
3ee953ef | 49 | allows the caller to sleep for an interval specified |
02afffe0 MK |
50 | with nanosecond precision. |
51 | It differs in allowing the caller to select the clock against | |
52 | which the sleep interval is to be measured, | |
53 | and in allowing the sleep interval to be specified as | |
54 | either an absolute or a relative value. | |
55 | ||
56 | The time values passed to and returned by this call are specified using | |
57 | .I timespec | |
58 | structures, defined as follows: | |
59 | .sp | |
60 | .in +4n | |
61 | .nf | |
62 | struct timespec { | |
63 | time_t tv_sec; /* seconds */ | |
64 | long tv_nsec; /* nanoseconds [0 .. 999999999] */ | |
65 | }; | |
66 | .fi | |
67 | .in | |
68 | ||
69 | The | |
70 | .I clock_id | |
71 | argument specifies the clock against which the sleep interval | |
72 | is to be measured. | |
73 | This argument can have one of the following values: | |
74 | .TP 17 | |
75 | .BR CLOCK_REALTIME | |
76 | A settable system-wide real-time clock. | |
77 | .TP | |
78 | .BR CLOCK_MONOTONIC | |
79 | A non-settable, monotonically increasing clock that measures time | |
80 | since some unspecified point in the past that does not change after | |
81 | system startup. | |
82 | .\" On Linux this clock measures time since boot. | |
83 | .TP | |
84 | .BR CLOCK_PROCESS_CPUTIME_ID | |
85 | A settable per-process clock that measures CPU time consumed | |
86 | by all threads in the process. | |
87 | .\" There is some trickery between glibc and the kernel | |
88 | .\" to deal with the CLOCK_PROCESS_CPUTIME_ID case. | |
89 | .PP | |
90 | See | |
91 | .BR clock_getres (3) | |
92 | for further details on these clocks. | |
93 | ||
94 | If | |
95 | .I flags | |
96 | is 0, then the value specified in | |
97 | .I request | |
98 | is interpreted as an interval relative to the current | |
99 | value of the clock specified by | |
100 | .IR clock_id . | |
101 | ||
102 | If | |
103 | .I flags | |
104 | is | |
105 | .BR TIMER_ABSTIME , | |
106 | then | |
107 | .I request | |
108 | is interpreted as an absolute time as measured by the clock, | |
109 | .IR clock_id . | |
110 | If | |
111 | .I request | |
112 | is less than or equal to the current value of the clock, | |
113 | then | |
114 | .BR clock_nanosleep () | |
115 | returns immediately without suspending the calling thread. | |
116 | ||
117 | .BR clock_nanosleep () | |
118 | suspends the execution of the calling thread | |
119 | until either at least the time specified by | |
120 | .IR request | |
121 | has elapsed, | |
122 | or a signal is delivered that causes a signal handler to be called or | |
123 | that terminates the process. | |
124 | ||
125 | If the call is interrupted by a signal handler, | |
126 | .BR clock_nanosleep () | |
127 | returns \-1, and sets | |
128 | .I errno | |
129 | to | |
130 | .BR EINTR . | |
131 | In addition, if | |
132 | .I remain | |
133 | is not NULL, and | |
134 | .I flags | |
135 | was not | |
136 | .BR TIMER_ABSTIME , | |
137 | it returns the remaining unslept time in | |
138 | .IR remain . | |
139 | This value can then be used to call | |
140 | .BR clock_nanosleep () | |
141 | again and complete a (relative) sleep. | |
142 | .SH "RETURN VALUE" | |
143 | On successfully sleeping for the requested interval, | |
144 | .BR clock_nanosleep () | |
145 | returns 0. | |
146 | If the call is interrupted by a signal handler or encounters an error, | |
147 | then it returns a positive error number. | |
148 | .SH ERRORS | |