Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sleep(3C) — DG/UX R4.11

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

alarm(2)

pause(2)

signal(2)

wait(2)

reentrant(3)



sleep(3C)                         SDK R4.11                        sleep(3C)


NAME
       sleep - suspend execution for interval

SYNOPSIS
       #include <unistd.h>

       unsigned sleep (unsigned seconds);

DESCRIPTION
       The current process is suspended from execution for the number of
       seconds specified by the argument.  The actual suspension time may be
       less than that requested because any caught signal will terminate the
       sleep following execution of that signal's catching routine.  Also,
       the suspension time may be longer than requested by an arbitrary
       amount because of the scheduling of other activity in the system.
       The value returned by sleep will be the ``unslept'' amount (the
       requested time minus the time actually slept) in case the caller had
       an alarm set to go off earlier than the end of the requested sleep
       time, or premature arousal because of another caught signal.

       The routine 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 sleep time 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 the sleep routine returns.  But if the sleep
       time is less than the time till such alarm, the prior alarm time is
       reset to go off at the same time it would have without the
       intervening sleep.


   Considerations for Threads Programming
                     +---------+-----------------------------+
                     |         |                      async- |
                     |function | reentrant   cancel   cancel |
                     |         |             point     safe  |
                     +---------+-----------------------------+
                     |sleep    |     Y         Y        N    |
                     +---------+-----------------------------+
       In a threaded application, only the thread issuing the sleep call
       suspends for the specified number of seconds. Other threads in the
       process are not affected. A threaded process does not use SIGALRM as
       do non-threaded processes.


SEE ALSO
       alarm(2), pause(2), signal(2), wait(2), reentrant(3).

EXAMPLE
       /* Program test for the sleep() function */

       #include <stdio.h>
       #include <unistd.h>

       unsigned int  hold;

       main() {
           printf("How long a nap (in seconds)?\n");
           scanf("%d", &hold);
           sleep(hold);
           printf("I'm awake again.\n");
       }

       If you execute the program test, and answer its query with 5, it
       pauses for 5 seconds, then generates the following:

       I'm awake again.

NOTES
       If the caller had an alarm that was going to go off during the call
       to sleep and the handler for SIGALRM was set to SIG_IGN, our
       implementation will use an internal handler to avoid a hanging
       process.  The caller's handler would then be restored before sleep
       returned.  This is an implementation specific detail and a user
       should not depend on this feature to be present in other UN*X
       implementations.


Licensed material--property of copyright holder(s)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026