[Previous] [Contents] [Next]

nanosleep()

Suspend a thread until a timeout or signal occurs

Synopsis:

#include <time.h>

int nanosleep( const struct timespec* rqtp,
               struct timespec* rmtp );

Library:

libc

Description:

The nanosleep() function causes the calling thread to be suspended from execution until either:

The suspension time may be longer than requested because the argument value is rounded up to be a multiple of the system timer resolution or because of scheduling and other system activity.

If the rmtp argument is non-NULL, the timespec structure referenced by it is updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept).

Returns:

0
The requested time has elapsed.
-1
The nanosleep() function was interrupted by a signal (errno is set).

Errors:

EAGAIN
All timers are in use. You'll have to wait for a process to release one.
EFAULT
A fault occurred trying to access the buffers provided.
EINTR
The nanosleep() function was interrupted by a signal.

Classification:

POSIX 1003.1 (Realtime Extensions)

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, clock_getres(), clock_gettime(), clock_settime(), sleep(), timer_create(), timer_delete(), timer_gettime(), timer_settime()


[Previous] [Contents] [Next]