clock_nanosleep Subroutine

Purpose

Specifies clock for high resolution sleep.

Syntax

#include <time.h>
 int clock_nanosleep(clockid_t clock_id, int flags,
       const struct timespec *rqtp, struct timespec *rmtp);

Description

If the TIMER_ABSTIME flag is not set in the flags argument, the clock_nanosleep subroutine causes the current thread to be suspended from execution until either the time interval specified by the rqtp argument has elapsed, or a signal is delivered to the calling thread and its action is to invoke a signal-catching function, or the process is terminated. The clock_id argument specifies the clock used to measure the time interval.

If the TIMER_ABSTIME flag is set in the flags argument, the clock_nanosleep subroutine causes the current thread to be suspended from execution until either the time value of the clock specified by clock_id reaches the absolute time specified by the rqtp argument, or a signal is delivered to the calling thread and its action is to invoke a signal-catching function, or the process is terminated. If, at the time of the call, the time value specified by rqtp is less than or equal to the time value of the specified clock, then the clock_nanosleep subroutine returns immediately and the calling process shall not be suspended.

The suspension time caused by this function might be longer than requested either 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 for the case of being interrupted by a signal, the suspension time for the relative clock_nanosleep subroutine (that is, with the TIMER_ABSTIME flag not set) shall not be less than the time interval specified by the rqtp argument, as measured by the corresponding clock. The suspension for the absolute clock_nanosleep subroutine (that is, with the TIMER_ABSTIME flag set) is in effect at least until the value of the corresponding clock reaches the absolute time specified by the rqtp argument, except for the case of being interrupted by a signal.

The clock_nanosleep subroutine has no effect on the action or blocking of any signal.

The subroutine fails if the clock_id argument refers to a process or a thread CPU-time clock.

Parameters

Item Description
clock_id Specifies the clock used to measure the time.
flags Identifies the type of timeout. If TIMER_ABSTIME is set, the time value pointed to by rqtp is an absolute time value; otherwise, it is a time interval.
rmtp Points to the timespec structure used to return the remaining amount of time in an interval (the requested time minus the time actually slept) if the sleep is interrupted.
rqtp Points to the timespec structure that contains requested sleep time.

Return Values

The clock_nanosleep subroutine returns 0 when the requested time has elapsed.

The clock_nanosleep subroutine returns the corresponding error value when it has been interrupted by a signal. For the relative clock_nanosleepsubroutine, when the rmtp argument is not NULL, the referenced timespec structure 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. The absolute clock_nanosleep subroutine has no effect on the structure referenced by the rmtp argument.

Error Codes

Item Description
EINTR The clock_nanosleep subroutine was interrupted by a signal.
EINVAL The rqtp parameter specified a nanosecond value less than 0 or greater than or equal to 1000 million; or the TIMER_ABSTIME flag was specified in the flags parameter and the rqtp parameter is outside the range for the clock specified by clock_id; or the clock_id parameter does not specify a known clock, or specifies the CPU-time clock of the calling thread.
ENOTSUP The clock_id argument specifies a clock for which the clock_nanosleep subroutine is not supported, such as a CPU-time clock.
ENOTSUP The subroutine is not supported with checkpoint-restarted processes.

Files

timer.h