# timer_getoverrun

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           timer_getoverrun, timer_gettime, timer_settime — per-process
           timers
    


## SYNOPSIS



           #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_);
    


## DESCRIPTION



           The _timer_gettime_() function shall store the amount of time until
           the specified timer, _timerid_ , expires and the reload value of the
           timer into the space pointed to by the _value_ argument. The
           _it_value_ member of this structure shall contain the amount of time
           before the timer expires, or zero if the timer is disarmed. This
           value is returned as the interval until timer expiration, even if
           the timer was armed with absolute time. The _it_interval_ member of
           _value_ shall contain the reload value last set by _timer_settime_().
    
           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_().
    


## RETURN VALUE



           If the _timer_getoverrun_() function succeeds, it shall return the
           timer expiration overrun count as explained above.
    
           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.
    


## ERRORS



           The _timer_settime_() function shall fail if:
    
           **EINVAL** A _value_ structure specified a nanosecond value less than
                  zero or greater than or equal to 1000 million, and the
                  _it_value_ member of that structure did not specify zero
                  seconds and nanoseconds.
    
           The _timer_settime_() function may fail if:
    
           **EINVAL** The _it_interval_ member of _value_ is not zero and the timer
                  was created with notification by creation of a new thread
                  (_sigev_sigev_notify_ was SIGEV_THREAD) and a fixed stack
                  address has been set in the thread attribute pointed to by
                  _sigev_notify_attributes_.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           Using fixed stack addresses is problematic when timer expiration
           is signaled by the creation of a new thread. Since it cannot be
           assumed that the thread created for one expiration is finished
           before the next expiration of the timer, it could happen that two
           threads use the same memory as a stack at the same time. This is
           invalid and produces undefined results.
    


## RATIONALE



           Practical clocks tick at a finite rate, with rates of 100 hertz
           and 1000 hertz being common. The inverse of this tick rate is the
           clock resolution, also called the clock granularity, which in
           either case is expressed as a time duration, being 10 milliseconds
           and 1 millisecond respectively for these common rates. The
           granularity of practical clocks implies that if one reads a given
           clock twice in rapid succession, one may get the same time value
           twice; and that timers must wait for the next clock tick after the
           theoretical expiration time, to ensure that a timer never returns
           too soon. Note also that the granularity of the clock may be
           significantly coarser than the resolution of the data format used
           to set and get time and interval values. Also note that some
           implementations may choose to adjust time and/or interval values
           to exactly match the ticks of the underlying clock.
    
           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.
    


## FUTURE DIRECTIONS



           None.
    


* * *