1TIMER_CREATE(3P)           POSIX Programmer's Manual          TIMER_CREATE(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       timer_create - create a per-process timer (REALTIME)
13

SYNOPSIS

15       #include <signal.h>
16       #include <time.h>
17
18       int timer_create(clockid_t clockid, struct sigevent *restrict evp,
19              timer_t *restrict timerid);
20
21

DESCRIPTION

23       The timer_create() function shall create a per-process timer using  the
24       specified clock, clock_id, as the timing base. The timer_create() func‐
25       tion shall return, in the location referenced by timerid, a timer ID of
26       type  timer_t  used to identify the timer in timer requests. This timer
27       ID shall be unique within  the  calling  process  until  the  timer  is
28       deleted.  The  particular clock, clock_id, is defined in <time.h>.  The
29       timer whose ID is returned shall be in a  disarmed  state  upon  return
30       from timer_create().
31
32       The  evp  argument,  if non-NULL, points to a sigevent structure.  This
33       structure, allocated by the application, defines the asynchronous noti‐
34       fication  to  occur as specified in Signal Generation and Delivery when
35       the timer expires. If the evp argument is NULL, the effect is as if the
36       evp argument pointed to a sigevent structure with the sigev_notify mem‐
37       ber having the value SIGEV_SIGNAL, the  sigev_signo  having  a  default
38       signal number, and the sigev_value member having the value of the timer
39       ID.
40
41       Each implementation shall define a set of clocks that can  be  used  as
42       timing  bases for per-process timers. All implementations shall support
43       a clock_id of CLOCK_REALTIME.  If the Monotonic Clock  option  is  sup‐
44       ported, implementations shall support a clock_id of CLOCK_MONOTONIC.
45
46       Per-process  timers  shall not be inherited by a child process across a
47       fork() and shall be disarmed and deleted by an exec.
48
49       If _POSIX_CPUTIME is defined, implementations  shall  support  clock_id
50       values representing the CPU-time clock of the calling process.
51
52       If  _POSIX_THREAD_CPUTIME  is  defined,  implementations  shall support
53       clock_id values representing the CPU-time clock of the calling thread.
54
55       It is implementation-defined whether  a  timer_create()  function  will
56       succeed  if  the  value defined by clock_id corresponds to the CPU-time
57       clock of a process or thread  different  from  the  process  or  thread
58       invoking the function.
59

RETURN VALUE

61       If  the  call succeeds, timer_create() shall return zero and update the
62       location referenced by timerid to a timer_t, which can be passed to the
63       per-process timer calls.  If an error occurs, the function shall return
64       a value of -1 and set errno to indicate the error. The value of timerid
65       is undefined if an error occurs.
66

ERRORS

68       The timer_create() function shall fail if:
69
70       EAGAIN The  system  lacks  sufficient signal queuing resources to honor
71              the request.
72
73       EAGAIN The calling process has already created all of the timers it  is
74              allowed by this implementation.
75
76       EINVAL The specified clock ID is not defined.
77
78       ENOTSUP
79              The  implementation  does  not  support  the creation of a timer
80              attached to the CPU-time clock that is specified by clock_id and
81              associated  with  a process or thread different from the process
82              or thread invoking timer_create().
83
84
85       The following sections are informative.
86

EXAMPLES

88       None.
89

APPLICATION USAGE

91       None.
92

RATIONALE

94   Periodic Timer Overrun and Resource Allocation
95       The specified timer facilities may deliver realtime signals  (that  is,
96       queued  signals)  on  implementations  that  support this option. Since
97       realtime applications cannot afford to lose notifications of  asynchro‐
98       nous events, like timer expirations or asynchronous I/O completions, it
99       must be possible to ensure that sufficient resources exist  to  deliver
100       the  signal when the event occurs. In general, this is not a difficulty
101       because there is a one-to-one correspondence between a  request  and  a
102       subsequent signal generation. If the request cannot allocate the signal
103       delivery resources, it can fail the call with an [EAGAIN] error.
104
105       Periodic timers are a special case. A single request  can  generate  an
106       unspecified  number of signals. This is not a problem if the requesting
107       process can service the signals as fast as  they  are  generated,  thus
108       making  the  signal delivery resources available for delivery of subse‐
109       quent periodic timer expiration signals. But, in general,  this  cannot
110       be  assured-processing  of  periodic timer signals may "overrun''; that
111       is, subsequent periodic timer expirations may  occur  before  the  cur‐
112       rently pending signal has been delivered.
113
114       Also,  for  signals,  according to the POSIX.1-1990 standard, if subse‐
115       quent occurrences of a pending signal are generated, it is  implementa‐
116       tion-defined  whether  a signal is delivered for each occurrence.  This
117       is not adequate for some  realtime  applications.  So  a  mechanism  is
118       required  to  allow  applications  to detect how many timer expirations
119       were delayed without requiring an indefinite amount of system resources
120       to store the delayed expirations.
121
122       The  specified  facilities  provide  for  an overrun count. The overrun
123       count is defined as the number of extra timer expirations that occurred
124       between  the  time  a timer expiration signal is generated and the time
125       the signal is delivered. The signal-catching function, if  it  is  con‐
126       cerned  with  overruns,  can  retrieve  this  count on entry. With this
127       method, a periodic timer only needs one "signal queuing resource"  that
128       can be allocated at the time of the timer_create() function call.
129
130       A function is defined to retrieve the overrun count so that an applica‐
131       tion need not allocate static storage to  contain  the  count,  and  an
132       implementation  need  not  update  this storage asynchronously on timer
133       expirations. But, for some high-frequency  periodic  applications,  the
134       overhead  of  an additional system call on each timer expiration may be
135       prohibitive. The functions, as defined,  permit  an  implementation  to
136       maintain  the overrun count in user space, associated with the timerid.
137       The timer_getoverrun() function can then be implemented as a macro that
138       uses  the timerid argument (which may just be a pointer to a user space
139       structure containing the counter) to locate the overrun count  with  no
140       system  call  overhead. Other implementations, less concerned with this
141       class of applications, can avoid the asynchronous update of user  space
142       by maintaining the count in a system structure at the cost of the extra
143       system call to obtain it.
144
145   Timer Expiration Signal Parameters
146       The Realtime Signals Extension option supports an  application-specific
147       datum  that is delivered to the extended signal handler.  This value is
148       explicitly specified by the application, along with the  signal  number
149       to  be delivered, in a sigevent structure. The type of the application-
150       defined value can be either an integer  constant  or  a  pointer.  This
151       explicit  specification  of the value, as opposed to always sending the
152       timer ID, was selected based on existing practice.
153
154       It is common practice for realtime applications (on  non-POSIX  systems
155       or realtime extended POSIX systems) to use the parameters of event han‐
156       dlers as the case label of a switch statement or as  a  pointer  to  an
157       application-defined  data  structure.  Since  timer_ids are dynamically
158       allocated by the timer_create() function, they can be used for  neither
159       of  these functions without additional application overhead in the sig‐
160       nal handler; for example, to search an array of saved timer IDs to  as‐
161       sociate the ID with a constant or application data structure.
162

FUTURE DIRECTIONS

164       None.
165

SEE ALSO

167       clock_getres(),  timer_delete(),  timer_getoverrun(),  the Base Defini‐
168       tions volume of IEEE Std 1003.1-2001, <time.h>
169
171       Portions of this text are reprinted and reproduced in  electronic  form
172       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
173       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
174       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
175       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
176       event of any discrepancy between this version and the original IEEE and
177       The Open Group Standard, the original IEEE and The Open Group  Standard
178       is  the  referee document. The original Standard can be obtained online
179       at http://www.opengroup.org/unix/online.html .
180
181
182
183IEEE/The Open Group                  2003                     TIMER_CREATE(3P)
Impressum