SLEEP(3)

NAME
sleep - suspend process execution for interval of seconds

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

DESCRIPTION
The sleep() function suspends execution of the calling process for seconds of time. System activity or time spent in processing the call may lengthen the sleep by a second.

If a timer is already running on the process its state is saved. If the value seconds is more than or equal to the remaining clock time for the saved timer, the sleep time is set to the remaining clock time. The state of the previous timer is restored after seconds has passed.

This function is implemented using setitimer(2); it requires eight system calls each time it is invoked. A similar but less compatible function can be obtained with a single select(2); such a function would not restart after signals, but would not interfere with other uses of setitimer(2).

RETURN VALUES
The sleep() function returns the number of seconds remaining to complete the operation. If sleep is interrupted or cannot allocate a timer it may will return the value needed to be passed to a subsequent sleep to complete the necessary delay. sleep() repeatedly until it returns zero may busy-wait until a timer is available.

SEE ALSO
setitimer(2), sigpause(2), usleep(3)

CAVEAT
In practice the FreeBSD implementation will not be interrupted: it will always return the original argument or zero. Code that depends on sleep being interrupted (using it as a timed pause, for example) needs to be recoded to use select(2) or some other delay mechanism. Code that calls sleep() repeatedly until it returns zero may busy-wait until a timer is available.

HISTORY
A sleep() function appeared in AT&T UNIX.