high resolution sleep
struct timespec *timeout,
function suspends execution of the calling thread for at least the given
timeout. Delivery of an unmasked signal terminates
this sleep early, even if
SA_RESTART is set with
sigaction(2) for the interrupting signal.
nanosleep() sleeps the full
timeout without interruption, it returns 0. Unless
NULL, it is set
nanosleep() is interrupted by a signal,
it returns -1 and the global variable errno is set to
EINTR. Unless remainder is
NULL, it is set to the unslept portion of the
nanosleep() returns -1 and the
global variable errno is set to indicate the
nanosleep() will fail if:
- The call is interrupted by the delivery of a signal.
- timeout specifies a nanosecond value less than zero or greater than or equal to one billion, or a second value less than zero.
- timeout points to memory that is not a valid part of the process address space.
- remainder is not
NULLand points to memory that is not a valid part of the process address space.
sleep(1), sigaction(2), sleep(3)
nanosleep() function conforms to
IEEE Std 1003.1-2008 (“POSIX.1”).
The predecessor of this system call,
sleep(), first appeared in
Version 2 AT&T UNIX. It was removed in
Version 7 AT&T UNIX and replaced with a C
library implementation based on
nanosleep() function first appeared in
IEEE Std 1003.1b-1993
This implementation of
appeared in NetBSD 1.3 and was ported to