1ALARM(P) POSIX Programmer's Manual ALARM(P)
2
3
4
6 alarm - schedule an alarm signal
7
9 #include <unistd.h>
10
11 unsigned alarm(unsigned seconds);
12
13
15 The alarm() function shall cause the system to generate a SIGALRM sig‐
16 nal for the process after the number of realtime seconds specified by
17 seconds have elapsed. Processor scheduling delays may prevent the
18 process from handling the signal as soon as it is generated.
19
20 If seconds is 0, a pending alarm request, if any, is canceled.
21
22 Alarm requests are not stacked; only one SIGALRM generation can be
23 scheduled in this manner. If the SIGALRM signal has not yet been gener‐
24 ated, the call shall result in rescheduling the time at which the
25 SIGALRM signal is generated.
26
27 Interactions between alarm() and any of setitimer(), ualarm(), or
28 usleep() are unspecified.
29
31 If there is a previous alarm() request with time remaining, alarm()
32 shall return a non-zero value that is the number of seconds until the
33 previous request would have generated a SIGALRM signal. Otherwise,
34 alarm() shall return 0.
35
37 The alarm() function is always successful, and no return value is
38 reserved to indicate an error.
39
40 The following sections are informative.
41
43 None.
44
46 The fork() function clears pending alarms in the child process. A new
47 process image created by one of the exec functions inherits the time
48 left to an alarm signal in the old process' image.
49
50 Application writers should note that the type of the argument seconds
51 and the return value of alarm() is unsigned. That means that a Strictly
52 Conforming POSIX System Interfaces Application cannot pass a value
53 greater than the minimum guaranteed value for {UINT_MAX}, which the
54 ISO C standard sets as 65535, and any application passing a larger
55 value is restricting its portability. A different type was considered,
56 but historical implementations, including those with a 16-bit int type,
57 consistently use either unsigned or int.
58
59 Application writers should be aware of possible interactions when the
60 same process uses both the alarm() and sleep() functions.
61
63 Many historical implementations (including Version 7 and System V)
64 allow an alarm to occur up to a second early. Other implementations
65 allow alarms up to half a second or one clock tick early or do not
66 allow them to occur early at all. The latter is considered most appro‐
67 priate, since it gives the most predictable behavior, especially since
68 the signal can always be delayed for an indefinite amount of time due
69 to scheduling. Applications can thus choose the seconds argument as the
70 minimum amount of time they wish to have elapse before the signal.
71
72 The term "realtime" here and elsewhere ( sleep(), times()) is intended
73 to mean "wall clock" time as common English usage, and has nothing to
74 do with "realtime operating systems". It is in contrast to virtual
75 time, which could be misinterpreted if just time were used.
76
77 In some implementations, including 4.3 BSD, very large values of the
78 seconds argument are silently rounded down to an implementation-defined
79 maximum value. This maximum is large enough (to the order of several
80 months) that the effect is not noticeable.
81
82 There were two possible choices for alarm generation in multi-threaded
83 applications: generation for the calling thread or generation for the
84 process. The first option would not have been particularly useful since
85 the alarm state is maintained on a per-process basis and the alarm that
86 is established by the last invocation of alarm() is the only one that
87 would be active.
88
89 Furthermore, allowing generation of an asynchronous signal for a thread
90 would have introduced an exception to the overall signal model. This
91 requires a compelling reason in order to be justified.
92
94 None.
95
97 alarm , exec() , fork() , getitimer() , pause() , sigaction() , sleep()
98 , ualarm() , usleep() , the Base Definitions volume of
99 IEEE Std 1003.1-2001, <signal.h>, <unistd.h>
100
102 Portions of this text are reprinted and reproduced in electronic form
103 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
104 -- Portable Operating System Interface (POSIX), The Open Group Base
105 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
106 Electrical and Electronics Engineers, Inc and The Open Group. In the
107 event of any discrepancy between this version and the original IEEE and
108 The Open Group Standard, the original IEEE and The Open Group Standard
109 is the referee document. The original Standard can be obtained online
110 at http://www.opengroup.org/unix/online.html .
111
112
113
114IEEE/The Open Group 2003 ALARM(P)