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