SLEEP(3)

NAME
sleep - suspend execution for an interval of seconds

SYNOPSIS
#include <unistd.h>
unsigned int
sleep(unsigned int seconds);

DESCRIPTION
The sleep() function suspends execution of the calling thread until at least the given number of seconds have elapsed or an unmasked signal is delivered to the calling thread.

This version of sleep() is implemented with nanosleep(2), so delivery of any unmasked signal will terminate the sleep early, even if SA_RESTART is set with sigaction(2) for the interrupting signal.

RETURN VALUES
If sleep() sleeps for the full count of seconds, it returns 0. Otherwise, sleep() returns the number of seconds remaining from the original request.

ERRORS
The sleep() function sets errno to EINTR if it is interrupted by the delivery of a signal.

SEE ALSO
sleep(1), nanosleep(2), sigaction(2)

STANDARDS
The sleep() function conforms to p1003.1-2008.

Setting errno is an extension to that specification.

HISTORY
A sleep() system call first appeared in AT&T UNIX. In AT&T UNIX, it was removed and replaced by a C library implementation based on signal(3) and alarm(3). For OpenBSD 2.1, it was reimplemented as a wrapper around the nanosleep(2) system call.