#include <time.h> int timer_getoverrun(timer_t timerid); int timer_gettime(timer_t timerid, struct itimerspec *value); int timer_settime(timer_t timerid, int flags, const struct itimerspec *restrict value, struct itimerspec *restrict ovalue);
The timer_settime() function shall set the time until the next expiration of the timer specified by timerid from the it_value member of the value argument and arm the timer if the it_value member of value is non-zero. If the specified timer was already armed when timer_settime() is called, this call shall reset the time until next expiration to the value specified. If the it_value member of value is zero, the timer shall be disarmed. The effect of disarming or resetting a timer with pending expiration notifications is unspecified.
If the flag TIMER_ABSTIME is not set in the argument flags, timer_settime() shall behave as if the time until next expiration is set to be equal to the interval specified by the it_value member of value. That is, the timer shall expire in it_value nanoseconds from when the call is made. If the flag TIMER_ABSTIME is set in the argument flags, timer_settime() shall behave as if the time until next expiration is set to be equal to the difference between the absolute time specified by the it_value member of value and the current value of the clock associated with timerid. That is, the timer shall expire when the clock reaches the value specified by the it_value member of value. If the specified time has already passed, the function shall succeed and the expiration notification shall be made.
The reload value of the timer shall be set to the value specified by the it_interval member of value. When a timer is armed with a non-zero it_interval, a periodic (or repetitive) timer is specified.
Time values that are between two consecutive non-negative integer multiples of the resolution of the specified timer shall be rounded up to the larger multiple of the resolution. Quantization error shall not cause the timer to expire earlier than the rounded time value.
If the argument ovalue is not NULL, the timer_settime() function shall store, in the location referenced by ovalue, a value representing the previous amount of time before the timer would have expired, or zero if the timer was disarmed, together with the previous timer reload value. Timers shall not expire before their scheduled time.
Only a single signal shall be queued to the process for a given timer at any point in time. When a timer for which a signal is still pending expires, no signal shall be queued, and a timer overrun shall occur. When a timer expiration signal is delivered to or accepted by a process, the timer_getoverrun() function shall return the timer expiration overrun count for the specified timer. The overrun count returned contains the number of extra timer expirations that occurred between the time the signal was generated (queued) and when it was delivered or accepted, up to but not including an implementation-defined maximum of {DELAYTIMER_MAX}. If the number of such extra expirations is greater than or equal to {DELAYTIMER_MAX}, then the overrun count shall be set to {DELAYTIMER_MAX}. The value returned by timer_getoverrun() shall apply to the most recent expiration signal delivery or acceptance for the timer. If no expiration signal has been delivered for the timer, the return value of timer_getoverrun() is unspecified.
The behavior is undefined if the value specified by the timerid argument to timer_getoverrun(), timer_gettime(), or timer_settime() does not correspond to a timer ID returned by timer_create() but not yet deleted by timer_delete().
If the timer_gettime() or timer_settime() functions succeed, a value of 0 shall be returned.
If an error occurs for any of these functions, the value -1 shall be returned, and errno set to indicate the error.
The timer_settime() function may fail if:
The following sections are informative.
This volume of POSIX.1-2017 defines functions that allow an application to determine the implementation-supported resolution for the clocks and requires an implementation to document the resolution supported for timers and nanosleep() if they differ from the supported clock resolution. This is more of a procurement issue than a runtime application issue.
If an implementation detects that the value specified by the timerid argument to timer_getoverrun(), timer_gettime(), or timer_settime() does not correspond to a timer ID returned by timer_create() but not yet deleted by timer_delete(), it is recommended that the function should fail and report an [EINVAL] error.
The Base Definitions volume of POSIX.1-2017, <time.h>
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .