High-resolution sleep (REALTIME). Suspends a process (or thread in a threaded program) from execution for the specified timer interval. This function is supported on OpenVMS Integrity servers and Alpha only. Format #include <time.h> int nanosleep (const struct timespec *rqtp, struct timespec *rmtp);
1 – Arguments
rqtp A pointer to the timespec data structure that defines the time interval during which the calling process or thread is suspended. rmtp A pointer to the timespec data structure that receives the amount of time remaining in the previously requested interval, or zero if the full interval has elapsed.
2 – Description
The nanosleep function suspends a process or thread until one of the following conditions is met: o The time interval specified by the rqtp argument has elapsed. o A signal is delivered to the calling process and the action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested because the argument value is rounded up to an integer multiple of the sleep resolution or because of the scheduling of other activity by the system. Except when interrupted by a signal, the suspension time is not less than the time specified by the rqtp argument (as measured by the system clock, CLOCK_REALTIME). The use of the nanosleep function has no effect on the action or blockage of any signal. If the requested time has elapsed, the call was successful and the nanosleep function returns zero. On failure, the nanosleep function returns -1 and sets errno to indicate the failure. The function fails if it has been interrupted by a signal, or if the rqtp argument specified a nanosecond value less than 0 or greater than or equal to 1 billion. If the rmtp argument is non-NULL, the timespec structure it references is updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept). If the rmtp argument is NULL, the remaining time is not returned. See also clock_getres, clock_gettime, clock_settime, and sleep.
3 – Return Values
0 Indicates success. The requested time has elapsed. -1 Indicates failure. The function call was unsuccessful or was interrupted by a signal; errno is set to one of the following values: o EINTR - The nanosleep function was interrupted by a signal. o EINVAL - The rqtp argument specified a nanosecond value less than 0 or greater than or equal to 1 billion.