[Previous]
[Contents]
[Next]

sleep()

suspend a process for a given length of time

Synopsis:

#include <unistd.h>
unsigned int sleep( unsigned int seconds );

Description:

The sleep() function suspends the calling process until the number of realtime seconds specified by the seconds argument have elapsed, or a signal whose action is to either terminate the process or call a signal handler is received. The suspension time may be greater than the requested amount, due to the scheduling of other, higher priority activity by the system.

Returns:

Zero if the full time specified was completed; otherwise the number of seconds remaining if interrupted by a signal.

Errors:

If an error occurs, errno is set to indicate the type of error:

EAGAIN
No timer resources available to satisfy the request.

Examples:

/*
 * The following program sleeps for the
 * number of seconds specified in argv[1].
 */
#include <stdlib.h>
#include <unistd.h>

void main( int argc, char **argv )

  {
    unsigned seconds;

    seconds = (unsigned) strtol( argv[1], NULL, 0 );
    sleep( seconds );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

alarm(), delay(), errno, timer_create(), timer_gettime(), timer_settime()


[Previous]
[Contents]
[Next]