TIMER_GETOVERRUN(3POSIX)
๐ธ TIMER_GETOVERRUN(3POSIX) โ the POSIX Programmer's Manual page, bestie edition ๐
okay so hi, you found the TIMER_GETOVERRUN page from the POSIX Programmer's Manual and honestly? it's a bop. three functions, one little timer family, lots of ~feelings~ about clocks. let's get into it โจ
๐ซถ PROLOG
so like, real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ โ so if you're on Linux, pls go check the corresponding Linux manual page for the deets on Linux behavior. OR, plot twist, the interface might not even be implemented on Linux at all ๐. vibe check accordingly.
โจ 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
okay bestie, sit down, we're doing a full deep dive ๐ง
timer_gettime() โ the "what's the countdown looking like" girl
timer_gettime() shall store the amount of time until the specified timer, timerid, expires, plus the reload value of the timer, into the space pointed to by the value argument.
- the
it_valuemember of this structure shall contain the amount of time before the timer expires โ or zero if the timer is disarmed. and no cap, this value gets returned as the interval until timer expiration, even if the timer was armed with absolute time. iconic behavior honestly. - the
it_intervalmember ofvalueshall contain the reload value last set bytimer_settime().
timer_settime() โ the "arming the timer" main character
timer_settime() 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_valuemember ofvalueis zero, the timer shall be disarmed. - > โ ๏ธ the effect of disarming or resetting a timer with pending expiration notifications is unspecified. we do not know her. proceed with caution, bestie.
relative vs absolute time, the plotline ๐ฌ
- if the flag
TIMER_ABSTIMEis not set in the argumentflags,timer_settime()shall behave as if the time until next expiration is set to be equal to the interval specified by theit_valuemember ofvalue. that is, the timer shall expire init_valuenanoseconds from when the call is made. - if the flag
TIMER_ABSTIMEis set in the argumentflags,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 theit_valuemember ofvalueand the current value of the clock associated withtimerid. that is, the timer shall expire when the clock reaches the value specified by theit_valuemember ofvalue. - and if the specified time has already passed? the function shall succeed and the expiration notification shall be made. she's forgiving like that ๐
reload value & periodic timers
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. it's giving ~loops~ โจ
quantization, aka clock rounding
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. no early birds here ๐
the ovalue argument
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. and timers shall not expire before their scheduled time. periodt.
overruns, the whole reason this page exists ๐ฏ
only a single signal shall be queued to the process for a given timer at any point in time. so 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. mystery box energy, we don't love it.
the big undefined behavior warning ๐
๐จ the behavior is undefined if the value specified by thetimeridargument totimer_getoverrun(),timer_gettime(), ortimer_settime()does not correspond to a timer ID returned bytimer_create()but not yet deleted bytimer_delete(). like, do NOT pass a stale timer id. fr fr.
๐ RETURN VALUE
- if the
timer_getoverrun()function succeeds, it shall return the timer expiration overrun count as explained above ๐ - if the
timer_gettime()ortimer_settime()functions succeed, a value of0shall be returned โจ - if an error occurs for any of these functions, the value
-1shall be returned, anderrnoset to indicate the error ๐
๐จ ERRORS
shall fail
EINVALโ avaluestructure specified a nanosecond value less than zero or greater than or equal to 1000 million, and theit_valuemember of that structure did not specify zero seconds and nanoseconds. yeah that's out of bounds bestie ๐
may fail
EINVALโ theit_intervalmember ofvalueis not zero and the timer was created with notification by creation of a new thread (sigev_sigev_notifywasSIGEV_THREAD) and a fixed stack address has been set in the thread attribute pointed to bysigev_notify_attributes.
the following sections are informative. (that's the manpage speaking, not me ๐ )
๐ EXAMPLES
None. ๐ญ literally nothing. no examples. we move.
๐ APPLICATION USAGE
using fixed stack addresses is problematic when timer expiration is signaled by the creation of a new thread. why? because it cannot be assumed that the thread created for one expiration is finished before the next expiration of the timer โ so it could happen that two threads use the same memory as a stack at the same time. that is invalid and produces undefined results. absolutely not the vibe. don't do it.
๐ง RATIONALE
okay this is the long lore section, stay with me ๐ฆ
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 ๐ณ
- 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, ngl.
and finally: 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. see, even the standard said "yeah, that should error out" ๐
๐ฎ FUTURE DIRECTIONS
None. the future is a mystery, but not for these functions apparently. ๐ซถ
๐ SEE ALSO
clock_getres()timer_create()- the Base Definitions volume of POSIX.1โ2017,
<time.h>
ยฉ๏ธ COPYRIGHT
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
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 .
and that's the whole page bestie!! ๐ ty for reading, you ate that. this was brought to you by IEEE/The Open Group, 2017, on the TIMER_GETOVERRUN(3POSIX) page โ mwah, go set some timers responsibly ๐๐โจ
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms