1ALARM(3P)                  POSIX Programmer's Manual                 ALARM(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       alarm — schedule an alarm signal
14

SYNOPSIS

16       #include <unistd.h>
17
18       unsigned alarm(unsigned seconds);
19

DESCRIPTION

21       The alarm() function shall cause the system to generate a SIGALRM  sig‐
22       nal  for  the process after the number of realtime seconds specified by
23       seconds have elapsed.  Processor  scheduling  delays  may  prevent  the
24       process from handling the signal as soon as it is generated.
25
26       If seconds is 0, a pending alarm request, if any, is canceled.
27
28       Alarm  requests  are  not  stacked;  only one SIGALRM generation can be
29       scheduled in this manner. If the SIGALRM signal has not yet been gener‐
30       ated,  the  call  shall  result  in  rescheduling the time at which the
31       SIGALRM signal is generated.
32
33       Interactions between alarm() and setitimer() are unspecified.
34

RETURN VALUE

36       If there is a previous alarm() request  with  time  remaining,  alarm()
37       shall  return  a non-zero value that is the number of seconds until the
38       previous request would have  generated  a  SIGALRM  signal.  Otherwise,
39       alarm() shall return 0.
40

ERRORS

42       The  alarm()  function  is  always  successful,  and no return value is
43       reserved to indicate an error.
44
45       The following sections are informative.
46

EXAMPLES

48       None.
49

APPLICATION USAGE

51       The fork() function clears pending alarms in the child process.  A  new
52       process  image  created  by one of the exec functions inherits the time
53       left to an alarm signal in the image of the old process.
54
55       Application developers should note that the type of the  argument  sec‐
56       onds  and  the  return value of alarm() is unsigned.  That means that a
57       Strictly Conforming POSIX System Interfaces Application cannot  pass  a
58       value  greater  than the minimum guaranteed value for {UINT_MAX}, which
59       the ISO C standard sets as 65535, and any application passing a  larger
60       value  is restricting its portability. A different type was considered,
61       but historical implementations, including those with a 16-bit int type,
62       consistently use either unsigned or int.
63
64       Application  developers  should  be aware of possible interactions when
65       the same process uses both the alarm() and sleep() functions.
66

RATIONALE

68       Many historical implementations (including  Version  7  and  System  V)
69       allow  an  alarm  to occur up to a second early.  Other implementations
70       allow alarms up to half a second or one clock  tick  early  or  do  not
71       allow  them to occur early at all. The latter is considered most appro‐
72       priate, since it gives the most predictable behavior, especially  since
73       the  signal  can always be delayed for an indefinite amount of time due
74       to scheduling. Applications can thus choose the seconds argument as the
75       minimum amount of time they wish to have elapse before the signal.
76
77       The term ``realtime'' here and elsewhere (sleep(), times()) is intended
78       to mean ``wall clock'' time as common English usage, and has nothing to
79       do  with  ``realtime  operating systems''. It is in contrast to virtual
80       time, which could be misinterpreted if just time were used.
81
82       In some implementations, including 4.3 BSD, very large  values  of  the
83       seconds  argument  are  silently rounded down to an implementation-spe‐
84       cific maximum value. This maximum is large enough (to the order of sev‐
85       eral months) that the effect is not noticeable.
86
87       There  were two possible choices for alarm generation in multi-threaded
88       applications: generation for the calling thread or generation  for  the
89       process. The first option would not have been particularly useful since
90       the alarm state is maintained on a per-process basis and the alarm that
91       is  established  by the last invocation of alarm() is the only one that
92       would be active.
93
94       Furthermore, allowing generation of an asynchronous signal for a thread
95       would  have  introduced  an exception to the overall signal model. This
96       requires a compelling reason in order to be justified.
97

FUTURE DIRECTIONS

99       None.
100

SEE ALSO

102       alarm(), exec, fork(), getitimer(), pause(), sigaction(), sleep()
103
104       The Base Definitions volume of POSIX.1‐2008, <signal.h>, <unistd.h>
105
107       Portions of this text are reprinted and reproduced in  electronic  form
108       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
109       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
110       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
111       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
112       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
113       event of any discrepancy between this version and the original IEEE and
114       The  Open Group Standard, the original IEEE and The Open Group Standard
115       is the referee document. The original Standard can be  obtained  online
116       at http://www.unix.org/online.html .
117
118       Any  typographical  or  formatting  errors that appear in this page are
119       most likely to have been introduced during the conversion of the source
120       files  to  man page format. To report such errors, see https://www.ker
121       nel.org/doc/man-pages/reporting_bugs.html .
122
123
124
125IEEE/The Open Group                  2013                            ALARM(3P)
Impressum