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