| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 4 |
.\" |
| 5 |
.TH timer_getoverrun 2 2025-10-29 "Linux man-pages 6.18" |
| 6 |
.SH NAME |
| 7 |
timer_getoverrun \- get overrun count for a POSIX per-process timer |
| 8 |
.SH LIBRARY |
| 9 |
Real-time library |
| 10 |
.RI ( librt ,\~ \-lrt ) |
| 11 |
.SH SYNOPSIS |
| 12 |
.nf |
| 13 |
.B #include <time.h> |
| 14 |
.P |
| 15 |
.BI "int timer_getoverrun(timer_t " timerid ); |
| 16 |
.fi |
| 17 |
.P |
| 18 |
.RS -4 |
| 19 |
Feature Test Macro Requirements for glibc (see |
| 20 |
.BR feature_test_macros (7)): |
| 21 |
.RE |
| 22 |
.P |
| 23 |
.BR timer_getoverrun (): |
| 24 |
.nf |
| 25 |
_POSIX_C_SOURCE >= 199309L |
| 26 |
.fi |
| 27 |
.SH DESCRIPTION |
| 28 |
.BR timer_getoverrun () |
| 29 |
returns the "overrun count" for the timer referred to by |
| 30 |
.IR timerid . |
| 31 |
An application can use the overrun count to accurately calculate the number |
| 32 |
of timer expirations that would have occurred over a given time interval. |
| 33 |
Timer overruns can occur both when receiving expiration notifications |
| 34 |
via signals |
| 35 |
.RB ( SIGEV_SIGNAL ), |
| 36 |
and via threads |
| 37 |
.RB ( SIGEV_THREAD ). |
| 38 |
.P |
| 39 |
When expiration notifications are delivered via a signal, |
| 40 |
overruns can occur as follows. |
| 41 |
Regardless of whether or not a real-time signal is used for |
| 42 |
timer notifications, |
| 43 |
the system queues at most one signal per timer. |
| 44 |
(This is the behavior specified by POSIX.1. |
| 45 |
The alternative, queuing one signal for each timer expiration, |
| 46 |
could easily result in overflowing the allowed limits for |
| 47 |
queued signals on the system.) |
| 48 |
Because of system scheduling delays, |
| 49 |
or because the signal may be temporarily blocked, |
| 50 |
there can be a delay between the time when the notification |
| 51 |
signal is generated and the time when it |
| 52 |
is delivered (e.g., caught by a signal handler) or accepted (e.g., using |
| 53 |
.BR sigwaitinfo (2)). |
| 54 |
In this interval, further timer expirations may occur. |
| 55 |
The timer overrun count is the number of additional |
| 56 |
timer expirations that occurred between the time when the signal |
| 57 |
was generated and when it was delivered or accepted. |
| 58 |
.P |
| 59 |
Timer overruns can also occur when expiration notifications |
| 60 |
are delivered via invocation of a thread, |
| 61 |
since there may be an arbitrary delay between an expiration of the timer |
| 62 |
and the invocation of the notification thread, |
| 63 |
and in that delay interval, additional timer expirations may occur. |
| 64 |
.SH RETURN VALUE |
| 65 |
On success, |
| 66 |
.BR timer_getoverrun () |
| 67 |
returns the overrun count of the specified timer; |
| 68 |
this count may be 0 if no overruns have occurred. |
| 69 |
On failure, \-1 is returned, and |
| 70 |
.I errno |
| 71 |
is set to indicate the error. |
| 72 |
.SH ERRORS |
| 73 |
.TP |
| 74 |
.B EINVAL |
| 75 |
.I timerid |
| 76 |
is not a valid timer ID. |
| 77 |
.SH VERSIONS |
| 78 |
When timer notifications are delivered via signals |
| 79 |
.RB ( SIGEV_SIGNAL ), |
| 80 |
on Linux it is also possible to obtain the overrun count via the |
| 81 |
.I si_overrun |
| 82 |
field of the |
| 83 |
.I siginfo_t |
| 84 |
structure (see |
| 85 |
.BR sigaction (2)). |
| 86 |
This allows an application to avoid the overhead of making |
| 87 |
a system call to obtain the overrun count, |
| 88 |
but is a nonportable extension to POSIX.1. |
| 89 |
.P |
| 90 |
POSIX.1 discusses timer overruns only in the context of |
| 91 |
timer notifications using signals. |
| 92 |
.\" FIXME . Austin bug filed, 11 Feb 09 |
| 93 |
.\" https://www.austingroupbugs.net/view.php?id=95 |
| 94 |
.SH STANDARDS |
| 95 |
POSIX.1-2024. |
| 96 |
.SH HISTORY |
| 97 |
Linux 2.6. |
| 98 |
POSIX.1-2001. |
| 99 |
.SH BUGS |
| 100 |
POSIX.1 specifies that if the timer overrun count |
| 101 |
is equal to or greater than an implementation-defined maximum, |
| 102 |
.BR DELAYTIMER_MAX , |
| 103 |
then |
| 104 |
.BR timer_getoverrun () |
| 105 |
should return |
| 106 |
.BR DELAYTIMER_MAX . |
| 107 |
However, before Linux 4.19, |
| 108 |
.\" http://bugzilla.kernel.org/show_bug.cgi?id=12665 |
| 109 |
if the timer overrun value exceeds the maximum representable integer, |
| 110 |
the counter cycles, starting once more from low values. |
| 111 |
Since Linux 4.19, |
| 112 |
.\" commit 78c9c4dfbf8c04883941445a195276bb4bb92c76 |
| 113 |
.BR timer_getoverrun () |
| 114 |
returns |
| 115 |
.B DELAYTIMER_MAX |
| 116 |
(defined as |
| 117 |
.B INT_MAX |
| 118 |
in |
| 119 |
.IR <limits.h> ) |
| 120 |
in this case (and the overrun value is reset to 0). |
| 121 |
.SH EXAMPLES |
| 122 |
See |
| 123 |
.BR timer_create (2). |
| 124 |
.SH SEE ALSO |
| 125 |
.BR clock_gettime (2), |
| 126 |
.BR sigaction (2), |
| 127 |
.BR signalfd (2), |
| 128 |
.BR sigwaitinfo (2), |
| 129 |
.BR timer_create (2), |
| 130 |
.BR timer_delete (2), |
| 131 |
.BR timer_settime (2), |
| 132 |
.BR signal (7), |
| 133 |
.BR time (7) |