alarm(2)
๐ alarm(2) โ bestie, it's literally the System Calls Manual and we're setting timers ๐
okay so this is alarm(2), from the System Calls Manual, and yes we're doing signals today. no cap, this one is short and iconic and honestly kind of a vibe. ๐
๐ธ NAME ๐ธ
alarm โ set an alarm clock for delivery of a signal โฐโจ
๐ง LIBRARY ๐ง
Standard C library (libc, -lc)
yeah girl you don't even have to link anything special, she comes free with libc ๐ซถ
โญ SYNOPSIS โญ
#include <unistd.h>
unsigned int alarm(unsigned int seconds);
๐ DESCRIPTION ๐
okay so what alarm() does is it arranges for a SIGALRM signal to be delivered to the calling process in seconds seconds. like, it's literally setting an alarm clock for your own self. main character behavior tbh. ๐ฅ
If seconds is zero, any pending alarm is canceled. bye bestie, alarm's over, we're not doing that anymore ๐
And in any event โ like, no matter what, every single time โ any previously set alarm() is canceled. the way that it just wipes the old one every time... it does not multitask, she's monogamous ๐
๐ฆ RETURN VALUE ๐ฆ
alarm() returns the number of seconds remaining until any previously scheduled alarm was due to be delivered, or zero if there was no previously scheduled alarm.
so it's like: "hey, this is how much time was left on the old one" โ and if you get 0 back, there was nothing waiting. either way you get the receipts โจ
๐ STANDARDS ๐
POSIX.1-2024.
certified, standardized, validated. the queen has been ratified ๐
๐ HISTORY ๐
4.3BSD, SVr4, POSIX.1-1988.
she's been doing this since forever and she's still slaying ๐
๐ NOTES ๐
alarm()andsetitimer(2)share the same timer โ calls to one will interfere with use of the other. this is the drama. do NOT use both at once unless you enjoy chaos ๐ญ- Alarms created by
alarm()are preserved acrossexecve(2)and are not inherited by children created viafork(2). so like, your alarm survives theexecve(2)glow-up, but the kids don't get it. no inheritance, sorry children ๐ sleep(3)may be implemented usingSIGALRM; mixing calls toalarm()andsleep(3)is a bad idea. fr fr. do not. this is your warning. ๐- Scheduling delays can, as ever, cause the execution of the process to be delayed by an arbitrary amount of time. so basically the universe might just be late and there's nothing you can do about it, that's just how it is โจ
๐ซถ SEE ALSO ๐ซถ
gettimeofday(2), pause(2), select(2), setitimer(2), sigaction(2), signal(2), timer_create(2), timerfd_create(2), sleep(3), time(7)
iykyk, go read em, they're all part of the family ๐
and that's the whole page bestie โ this lovely little writeup came from Linux man-pages 6.20, dated 2026-02-08, and the page itself is alarm(2). go set a timer and live your life ๐
โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- Copyright 1993, Ian Jackson <iwj10@cus.cam.ac.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms