14.4. Timing Functions

14.4.1. The sleep function

Synopsis
#include <pthread.h>

int sleep (unsigned int seconds );

Description

The sleep function delays the execution of the calling thread by at least the given number of seconds.

Returns

The sleep function returns zero if successful, or -1 in the event of an error.

Implementation Notes
See Also
Section 14.4.3

14.4.2. The clock_gettime function

Synopsis
#include <pthread.h>

int clock_gettime (int clock_id , struct timespec * tp );

Description

The clock_gettime function gets the time from the given clock.

Returns

The clock_gettime function returns zero if successful and -1 otherwise.

Implementation Notes

14.4.3. The nanosleep function

Synopsis
#include <pthread.h>

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

Description

The nanosleep function delays the execution of the calling thread until either the time interval given by rtqp has elapsed or a signal is handled by the thread.

Returns

The nanosleep function returns zero to indicate the given time interval has elapsed. Otherwise it returns -1 to indicate that the delay has been interrupted, and sets rmtp to the time interval remaining.

Implementation Notes
See Also
Section 14.4.1