ALARM(3POSIX)
πΈ ALARM(3POSIX) πΈ
okay bestie, welcome to ALARM(3POSIX), straight out of the POSIX Programmer's Manual π she's iconic, she's foundational, and she's about to schedule a signal for you. periodt.
π¨ PROLOG (read this first, i'm serious) π¨
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so pls consult the corresponding Linux manual page for the deets on Linux behavior. or, plot twist, the interface may not even be implemented on Linux at all π. vibe check your platform first, fr fr.
β¨ NAME β¨
alarm β schedule an alarm signal π
π SYNOPSIS π
#include <unistd.h>
unsigned alarm(unsigned seconds);
π DESCRIPTION π
so here's the tea: the alarm() function shall cause the system to generate a SIGALRM signal for the process after the number of realtime seconds specified by seconds have elapsed. lowkey important caveat though β processor scheduling delays may prevent the process from handling the signal as soon as it is generated. so like, don't expect it at the exact nanosecond, okay? the system is doing her best π₯Ί.
- If
secondsis0, a pending alarm request, if any, is canceled. bye bye alarm π - Alarm requests are not stacked β only one
SIGALRMgeneration can be scheduled in this manner. so no, you can't queue up five alarms and have a little alarm party. one at a time, babe. - If the
SIGALRMsignal has not yet been generated, the call shall result in rescheduling the time at which theSIGALRMsignal is generated.
π Interactions betweenalarm()andsetitimer()are unspecified. it's giving "undefined behavior," it's giving "don't do that," it's giving "pick one and commit." you have been warned.
π₯ RETURN VALUE π₯
- If there is a previous
alarm()request with time remaining,alarm()shall return a non-zero value that is the number of seconds until the previous request would have generated aSIGALRMsignal β³ - Otherwise,
alarm()shall return0.
π¦ ERRORS π¦
not to be dramatic but... the alarm() function is always successful, and no return value is reserved to indicate an error π. she doesn't miss. she doesn't fail. she just alarms.
The following sections are informative. (translation: the juicy academic bits below are context, not rules β¨)
π EXAMPLES π
None. π truly nothing. the void. the emptiness. moving on.
π APPLICATION USAGE π
okay so important lore:
- The
fork()function clears pending alarms in the child process. - A new process image created by one of the
execfunctions inherits the time left to an alarm signal in the image of the old process.
Application developers should note that the type of the argument seconds and the return value of alarm() is unsigned. That means that a Strictly Conforming POSIX System Interfaces Application cannot pass a value greater than the minimum guaranteed value for {UINT_MAX}, which the ISO C standard sets as 65535, and any application passing a larger value is restricting its portability. A different type was considered, but historical implementations β including those with a 16-bit int type β consistently use either unsigned or int. so yeah, that's the history bestie, we're stuck with it π.
Also, application developers should be aware of possible interactions when the same process uses both the alarm() and sleep() functions. they're in the same friend group, and it gets messy. π
π§ RATIONALE π§
grab a snack, this is the lore dump:
Many historical implementations (including Version 7 and System V) allow an alarm to occur up to a second early. Other implementations allow alarms up to half a second or one clock tick early, or do not allow them to occur early at all. The latter is considered most appropriate, since it gives the most predictable behavior β especially since the signal can always be delayed for an indefinite amount of time due to scheduling. Applications can thus choose the seconds argument as the minimum amount of time they wish to have elapse before the signal. minimum, not exact. noted? noted. βοΈ
The term realtime'' here and elsewhere (`sleep()`, `times()`) is intended to mean wall clock'' time as common English usage, and has nothing to do with ``realtime operating systems''. It is in contrast to virtual time, which could be misinterpreted if just time were used. iykyk π°οΈ
In some implementations, including 4.3 BSD, very large values of the seconds argument are silently rounded down to an implementation-specific maximum value. This maximum is large enough (to the order of several months) that the effect is not noticeable. so like, it's fine. probably. π€·
There were two possible choices for alarm generation in multi-threaded applications: generation for the calling thread, or generation for the process. The first option would not have been particularly useful since the alarm state is maintained on a per-process basis and the alarm that is established by the last invocation of alarm() is the only one that would be active. only the last one. the final one. the main character π
Furthermore, allowing generation of an asynchronous signal for a thread would have introduced an exception to the overall signal model. This requires a compelling reason in order to be justified. and they didn't have one. so. no.
β FUTURE DIRECTIONS β
None. she is who she is. no notes. π
π SEE ALSO π
alarm()execfork()getitimer()pause()sigaction()sleep()
The Base Definitions volume of POSIX.1β2017: <signal.h>, <unistd.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!! π this one came to you courtesy of IEEE/The Open Group, 2017 β yes the footer said ALARM(3POSIX), and yes we're folding that in right here like the little bow on top of the gift π. go schedule something. responsibly. slay. β¨
π¦ 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