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