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() and setitimer(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 across execve(2) and are not inherited by children created via fork(2). so like, your alarm survives the execve(2) glow-up, but the kids don't get it. no inheritance, sorry children ๐Ÿ™ˆ
  • sleep(3) may be implemented using SIGALRM; mixing calls to alarm() and sleep(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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms