1CLOCK_NANOSLEEP(2) Linux Programmer's Manual CLOCK_NANOSLEEP(2)
2
3
4
6 clock_nanosleep - high-resolution sleep with specifiable clock
7
9 #include <time.h>
10
11 int clock_nanosleep(clockid_t clock_id, int flags,
12 const struct timespec *request,
13 struct timespec *remain);
14
15 Link with -lrt.
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 clock_nanosleep(): _XOPEN_SOURCE >= 600
20
22 Like nanosleep(2), clock_nanosleep() allows the caller to sleep for an
23 interval specified with nanosecond precision. It differs in allowing
24 the caller to select the clock against which the sleep interval is to
25 be measured, and in allowing the sleep interval to be specified as
26 either an absolute or a relative value.
27
28 The time values passed to and returned by this call are specified using
29 timespec structures, defined as follows:
30
31 struct timespec {
32 time_t tv_sec; /* seconds */
33 long tv_nsec; /* nanoseconds [0 .. 999999999] */
34 };
35
36 The clock_id argument specifies the clock against which the sleep
37 interval is to be measured. This argument can have one of the follow‐
38 ing values:
39
40 CLOCK_REALTIME A settable system-wide real-time clock.
41
42 CLOCK_MONOTONIC A nonsettable, monotonically increasing clock that
43 measures time since some unspecified point in the past
44 that does not change after system startup.
45
46 CLOCK_PROCESS_CPUTIME_ID
47 A settable per-process clock that measures CPU time
48 consumed by all threads in the process.
49
50 See clock_getres(2) for further details on these clocks.
51
52 If flags is 0, then the value specified in request is interpreted as an
53 interval relative to the current value of the clock specified by
54 clock_id.
55
56 If flags is TIMER_ABSTIME, then request is interpreted as an absolute
57 time as measured by the clock, clock_id. If request is less than or
58 equal to the current value of the clock, then clock_nanosleep() returns
59 immediately without suspending the calling thread.
60
61 clock_nanosleep() suspends the execution of the calling thread until
62 either at least the time specified by request has elapsed, or a signal
63 is delivered that causes a signal handler to be called or that termi‐
64 nates the process.
65
66 If the call is interrupted by a signal handler, clock_nanosleep()
67 returns -1, and sets errno to EINTR. In addition, if remain is not
68 NULL, and flags was not TIMER_ABSTIME, it returns the remaining unslept
69 time in remain. This value can then be used to call clock_nanosleep()
70 again and complete a (relative) sleep.
71
73 On successfully sleeping for the requested interval, clock_nanosleep()