nanosleep

Causes the current thread to be suspended from execution for the specified interval.

Library:LibC
Classification:Single UNIX
Service:Time

Syntax

  #include <time.h> 
   
  int nanosleep (
     const struct timespec   *rqtp,
     struct timespec         *rmtp );
  

Parameters

rqtp

(IN) Points to the interval that the thread should sleep.

rmtp

(OUT) Points to the time remaining in the interval when a signal interrupts nanosleep.

Return Values

If nanosleep returns because the interval has expired, it returns 0.

If nanosleep returns because of a signal interrupt, it returns -1 and sets errno. If the rmtp parameter is non-NULL, the timespec structure referenced by it is updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept). If the rmtp parameter is NULL, the remaining time is not returned.

If nanosleep fails, it returns -1 and sets errno.

Decimal

Constant

Description

9

EINVAL

The rqtp parameter specifies a nanosecond value less than zero or greater than or equal to 1000 million.

63

EINTR

A signal interrupted the operation.

105

ENOCONTEXT

No thread context is present.

Remarks

Unless interrupted by an interrupt, nanosleep suspends the thread for at least the specified interval. The interval might be longer than the specified interval, depending upon what else the system is scheduling.

See Also