clock_nanosleep - high-resolution sleep with specifiable clock
#include <time.h>
int clock_nanosleep(clockid_t clockid, int flags,
const struct timespec *t,
struct timespec *_Nullable remain);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
Like nanosleep(2), clock_nanosleep() allows the calling thread to sleep for an interval specified with nanosecond precision. It differs in allowing the caller to select the clock against which the sleep interval is to be measured, and in allowing the sleep interval to be specified as either an absolute or a relative value.
The time values passed to and returned by this call are specified using timespec(3) structures.
The clockid
argument specifies the clock against which the
sleep interval is to be measured. This argument can have one of the
following values:
A settable system-wide real-time clock.
A system-wide clock derived from wall-clock time but counting leap seconds.
A nonsettable, monotonically increasing clock that measures time since some unspecified point in the past that does not change after system startup.
Identical to CLOCK_MONOTONIC, except that it also includes any time that the system is suspended.
A settable per-process clock that measures CPU time consumed by all threads in the process.
See clock_getres(2) for further details on these
clocks. In addition, the CPU clock IDs returned by
clock_getcpuclockid(3) and
pthread_getcpuclockid(3) can also be passed in
clockid
.
If flags
is 0, then the value specified in t
is
interpreted as an interval relative to the current value of the clock
specified by clockid
.
If flags
is TIMER_ABSTIME, then t
is interpreted as an absolute time as measured by the clock,
clockid
. If t
is less than or equal to the current
value of the clock, then clock_nanosleep() returns
immediately without suspending the calling thread.
clock_nanosleep() suspends the execution of the
calling thread until either at least the time specified by t
has elapsed, or a signal is delivered that causes a signal handler to be
called or that terminates the process.
If the call is interrupted by a signal handler,
clock_nanosleep() fails with the error
EINTR. In addition, if remain
is not NULL, and
flags
was not TIMER_ABSTIME, it returns the
remaining unslept time in remain
. This value can then be used
to call clock_nanosleep() again and complete a
(relative) sleep.
On successfully sleeping for the requested interval, clock_nanosleep() returns 0. If the call is interrupted by a signal handler or encounters an error, then it returns one of the positive error number listed in ERRORS.
clock_getres(2), nanosleep(2), restart_syscall(2), timer_create(2), sleep(3), timespec(3), usleep(3), time(7)