OpenBSD manual page server

Manual Page Search Parameters

SLEEP(3) Library Functions Manual SLEEP(3)

sleepsuspend execution for an interval of seconds

#include <unistd.h>

unsigned int
sleep(unsigned int seconds);

The () 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 () 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.

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

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

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

The sleep() function conforms to IEEE Std 1003.1-2008 (“POSIX.1”).

Setting errno is an extension to that specification.

A sleep() system call first appeared in Version 2 AT&T UNIX. In Version 7 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.

March 31, 2022 OpenBSD-7.6