TIMER_CREATE(2)
π TIMER_CREATE π
the iconic per-process timer maker β straight out of the System Calls Manual, section 2, and yes she's serving REALTIME realness π
πΈ NAME πΈ
timer_create β create a per-process timer (REALTIME)
π LIBRARY π
POSIX Real-time Library (librt, -lrt) β link her in, bestie, or she simply will not show up π
β¨ SYNOPSIS β¨
#include <time.h>
#include <signal.h>
int
timer_create(clockid_t clockid, struct sigevent *restrict evp,
timer_t *restrict timerid);
π¦ DESCRIPTION π¦
okay so listen. timer_create() is the system call that creates a per-process timer using the clock you hand it β clock_id β as the timing base. slay.
She gives you back, in the spot that timerid points to, a timer ID of type timer_t. that ID is what you use to identify the timer in all your future timer requests. and it's unique within the calling process until the timer gets deleted β main character exclusivity, no cap. the specific clock, clock_id, is defined over in <time.h>. also, the timer whose ID you just got back? she arrives disarmed</> β no ticking, no drama, just vibes until you arm her.
The evp argument β if it's non-NULL β points to a sigevent structure. you allocate that yourself, and it defines the asynchronous notification that happens when the timer expires. it's giving "here's what to do when the moment comes."
If evp->sigev_notify is SIGEV_SIGNO or SIGEV_THREAD_ID, then the signal named in evp->sigev_signo gets sent to:
- the calling process β when it's
SIGEV_SIGNO - the thread whose LWP ID is
evp->sigev_notify_thread_idβ when it'sSIGEV_THREAD_ID
and the info attached to that queued signal includes all of this π«Ά:
si_codeβSI_TIMERsi_valueβ the value stored inevp->sigev_valuesi_timeridβ timer IDsi_overrunβ timer overrun countsi_errnoβ if timer overrun is{DELAYTIMER_MAX}, an error code defined in<errno.h>
If the evp argument is NULL? literally the same as if you'd pointed evp at a sigevent structure where the sigev_notify member has the value SIGEV_SIGNAL, the sigev_signo has a default signal number (SIGALRM), and the sigev_value member has the value of the timer ID. the defaults ate, honestly.
This implementation supports a clock_id of CLOCK_REALTIME or CLOCK_MONOTONIC. that's the whole menu, bestie.
π¨ okay this next bit is the "read the fine print" moment. Ifevp->sigev_notifyisSIGEV_THREADandsev->sigev_notify_attributesis notNULL, and if the attribute pointed to bysev->sigev_notify_attributeshas a thread stack address specified by a call topthread_attr_setstack()orpthread_attr_setstackaddr(), then the results are unspecified if the signal is generated more than once. not a vibe. be careful out there π
π RETURN VALUES π
If the call succeeds, timer_create() returns zero and updates the location referenced by timerid to a timer_t, which you can then pass to the per-process timer calls. queen behavior.
If an error occurs, the system call returns a value of -1 and the global variable errno is set to indicate the error. and heads up: the value of timerid is undefined if an error occurs. don't go reading her, she's not okay π
π ERRORS π
The timer_create() system call will fail if:
[EAGAIN]β The calling process has already created all of the timers it is allowed by this implementation. (timer cap reached, bestie, no more for you π)[EINVAL]β The specified clock ID is not supported.[EINVAL]β The specified asynchronous notification method is not supported.[EFAULT]β Any arguments point outside the allocated address space or there is a memory protection fault.
π SEE ALSO π
clock_getres(2), timer_delete(2), timer_getoverrun(2), sigevent(3), siginfo(3)
the whole friend group, go say hi π
β STANDARDS β
The timer_create() system call conforms to IEEE Std 1003.1-2004 (βPOSIX.1β). certified, stamped, official π₯
π§ HISTORY π§
Support for POSIX per-process timer first appeared in FreeBSD 7.0. a true OG.
and that's the whole page, bestie π this one came to you from Debian, dated July 15, 2016 β mwah, take care of her πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms