NANOSLEEP(2) | System Calls Manual | NANOSLEEP(2) |
nanosleep
— high
resolution sleep
Standard C Library (libc, -lc)
#include
<time.h>
int
clock_nanosleep
(clockid_t
clock_id, int flags, const
struct timespec *rqtp, struct timespec
*rmtp);
int
nanosleep
(const struct timespec
*rqtp, struct timespec *rmtp);
If the TIMER_ABSTIME
flag is not set in
the flags argument, then
clock_nanosleep
()
suspends execution of the calling thread until either the time interval
specified by the rqtp argument has elapsed, or a
signal is delivered to the calling process and its action is to invoke a
signal-catching function or to terminate the process. The clock used to
measure the time is specified by the clock_id
argument.
If the
TIMER_ABSTIME
flag is set in the
flags argument, then
clock_nanosleep
()
suspends execution of the calling thread until either the value of the clock
specified by the clock_id argument reaches the
absolute time specified by the rqtp argument, or a
signal is delivered to the calling process and its action is to invoke a
signal-catching function or to terminate the process. If, at the time of the
call, the time value specified by rqtp is less than or
equal to the time value of the specified clock, then
clock_nanosleep
() returns immediately and the
calling thread is not suspended.
The suspension time may be longer than requested due to the
scheduling of other activity by the system. An unmasked signal will
terminate the sleep early, regardless of the
SA_RESTART
value on the interrupting signal. The
rqtp and rmtp arguments can
point to the same object.
The following clock_id values are supported:
The
nanosleep
()
function behaves like clock_nanosleep
() with a
clock_id argument of
CLOCK_REALTIME
and without the
TIMER_ABSTIME
flag in the
flags argument.
These functions return zero when the requested time has elapsed.
If these functions return for any other reason, then
clock_nanosleep
() will directly return the error
number, and nanosleep
() will return -1 with the
global variable errno set to indicate the error. If a
relative sleep is interrupted by a signal and rmtp is
non-NULL
, the timespec structure it references is
updated to contain the unslept amount (the request time minus the time
actually slept).
These functions can fail with the following errors.
EFAULT
]EINTR
]EINVAL
]EINVAL
]EINVAL
]CLOCK_THREAD_CPUTIME_ID
or an unrecognized
value.ENOTSUP
]clock_nanosleep
().These functions conform to IEEE Std 1003.1-2008 (“POSIX.1”).
March 17, 2017 | Debian |