sleep(3) CLIX sleep(3)
NAME
sleep - Suspends execution for a specified time interval
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
unsigned int sleep(
unsigned int seconds );
PARAMETERS
seconds Specifies the number of seconds to suspend execution.
DESCRIPTION
The sleep() function suspends execution of the current process for the
interval specified by seconds. The actual suspension time may be less
than that requested for the following reasons:
⊕ Scheduled wakeups occur at fixed 1-second intervals, (on the second,
according to an internal clock).
⊕ Any caught signal will terminate sleep() following execution of that
signal's catching routine.
Also, the suspension time may be longer than requested by an arbitrary
amount due to the scheduling of other activity in the system.
The function is implemented by setting an alarm signal and pausing until
it (or some other signal) occurs. The previous state of the alarm signal
is saved and restored. The calling program may have set up an alarm
signal before calling sleep(). If the time requested exceeds the time
until such alarm signal, the process sleeps only until the alarm signal
would have occurred. The caller's alarm catch routine is executed just
before sleep() returns. But if the time requested is less than the time
util such alarm, the prior alarm time is reset to go off at the same time
it would have without the intervening sleep() call.
EXAMPLES
To sleep for some number of seconds, counting the number of signals
received:
int num_signals_received = 0;
for (;;) {
num_seconds = sleep(num_seconds);
if (num_seconds == 0)
2/94 - Intergraph Corporation 1
sleep(3) CLIX sleep(3)
break;
num_signals_received++;
}
RETURN VALUES
If sleep() returns because the requested time has elapsed, a 0 value is
returned. If sleep() returns due to delivery of a signal, the value
returned is the unslept amount (the requested time minus the time actually
slept) in seconds.
ERRORS
No errors are defined.
RELATED INFORMATION
Functions: alarm(2), pause(2), sigaction(2), signal(2)
2 Intergraph Corporation - 2/94