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

NAME

12       alarm - schedule an alarm signal
13

SYNOPSIS

15       #include <unistd.h>
16
17       unsigned alarm(unsigned seconds);
18
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  any  of  setitimer(),  ualarm(),  or
34       usleep() are unspecified.
35

RETURN VALUE

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

ERRORS

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

EXAMPLES

49       None.
50

APPLICATION USAGE

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

RATIONALE

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

FUTURE DIRECTIONS

100       None.
101

SEE ALSO

103       alarm,  exec(),  fork(),  getitimer(),  pause(),  sigaction(), sleep(),
104       ualarm(),    usleep(),    the    Base     Definitions     volume     of
105       IEEE Std 1003.1-2001, <signal.h>, <unistd.h>
106
108       Portions  of  this text are reprinted and reproduced in electronic form
109       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
110       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
111       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
112       Electrical  and  Electronics  Engineers, Inc and The Open Group. 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.opengroup.org/unix/online.html .
117
118
119
120IEEE/The Open Group                  2003                            ALARM(3P)
Impressum