Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sleep(K) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     SLEEP(K)                  UNIX System V                  SLEEP(K)



     Name
          sleep - suspends processing temporarily

     Syntax
          #include "sys/param.h"

          int
          sleep(address, priority)
          caddr_t address;
          int priority;

     Description
          sleep suspends task time processing in a driver.  Its
          behavior and functionality is not at all like that of the
          sleep(S) system call.  For a temporary halt in the execution
          of your driver use the delay(K) routine.  sleep should be
          used when it is necessary for the driver to wait until a
          resource is available or an I/O request has completed before
          continuing task time execution.  It is not guaranteed that
          when sleep returns, the event or resource that the driver
          has been waiting for will have occurred.

     Notes
          This routine must not be called at interrupt time or from
          the xxinit routine.

     Parameters
          address is a number the system uses for identifying the
          sleeping process in the process table.  This number should
          be chosen so that it is unique to those processes put to
          sleep by your driver.  A good method for deriving a unique
          number is to use the address of a global variable that has
          been declared in your driver.  Addresses of static variables
          are not guaranteed to be unique.  During debugging it is
          useful for the device driver writer to display this number,
          since it is possible to use the shell command ps -el to
          identify which processes are sleeping in your driver by
          examining the values reported in the WCHAN column.

          priority determines the priority of the process when it
          awakens.  This value is used by the scheduler to determine
          execution order in the run queue.  A lower priority places
          the process nearer the top of the run queue.  In addition
          the value of priority is also used to determine whether the
          sleeping process can be interrupted by a software signal.
          If priority is less than PZERO, then the sleeping process
          cannot be interrupted by a software signal.  A process
          should only sleep at a priority less than PZERO if it is
          guaranteed that the event it is waiting for will occur
          within a short time. In general, processes should sleep at
          priorities greater than PZERO so that users are able to
          force termination of their processes by a software signal if
          an error occurs.

     Return Values
          sleep returns 0 (zero) if a wakeup(K) routine has been
          called using the same address that was specified in the
          sleep call, or it returns 1 if the priority used has been
          ORed with PCATCH and the sleeping process has been sent a
          software signal.

     Notes
          If priority has not been ORed with PCATCH and the sleeping
          process is interrupted by a software signal, sleep will not
          return control to the device driver.  Instead sleep will
          longjmp(K) back to the process state just after the system
          call was made.  The system call invoked by the user process
          will return -1 and errno will be set to EINTR.  If the
          device driver has set flags or temporarily allocated memory
          that should be cleared or freed when sleep is interrupted,
          OR the PCATCH constant into priority.  This causes control
          to return to the driver on a signal. The driver should then
          restore any temporary resources it was using, set u.u_error
          to EINTR, and return -1.  See the example following the
          discussion of the wakeup routine for more information.

     See Also
          timeout(K), wakeup(K)

                                                      (printed 7/6/89)



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