xref: /freebsd/lib/libsys/timer_create.2 (revision b670c9bafc0e31c7609969bf374b2e80bdc00211)
1.\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice(s), this list of conditions and the following disclaimer as
9.\"    the first lines of this file unmodified other than the possible
10.\"    addition of one or more copyright notices.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice(s), this list of conditions and the following disclaimer in
13.\"    the documentation and/or other materials provided with the
14.\"    distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.Dd July 15, 2016
29.Dt TIMER_CREATE 2
30.Os
31.Sh NAME
32.Nm timer_create
33.Nd "create a per-process timer (REALTIME)"
34.Sh LIBRARY
35.Lb librt
36.Sh SYNOPSIS
37.In time.h
38.In signal.h
39.Ft int
40.Fo timer_create
41.Fa "clockid_t clockid" "struct sigevent *restrict evp"
42.Fa "timer_t *restrict timerid"
43.Fc
44.Sh DESCRIPTION
45The
46.Fn timer_create
47system call creates a per-process timer using the specified clock,
48.Fa clock_id ,
49as the timing base.
50The
51.Fn timer_create
52system call returns, in the location referenced by
53.Fa timerid ,
54a timer ID of type
55.Vt timer_t
56used to identify the timer in timer requests.
57This timer ID is unique within the calling process until the timer is deleted.
58The particular clock,
59.Fa clock_id ,
60is defined in
61.In time.h .
62The timer whose ID is returned is in a disarmed state upon return from
63.Fn timer_create .
64.Pp
65The
66.Fa evp
67argument, if
68.Pf non- Dv NULL ,
69points to a
70.Vt sigevent
71structure.
72This structure,
73allocated by the application, defines the asynchronous notification to occur
74when the timer expires.
75.Pp
76If
77.Fa evp->sigev_notify
78is
79.Dv SIGEV_SIGNO
80or
81.Dv SIGEV_THREAD_ID ,
82the signal specified in
83.Fa evp->sigev_signo
84will be sent to the calling process
85.Pq Dv SIGEV_SIGNO
86or to the thread whose LWP ID is
87.Fa evp->sigev_notify_thread_id
88.Pq Dv SIGEV_THREAD_ID .
89The information for the queued signal will include:
90.Bl -column ".Va si_value"
91.It Sy Member Ta Sy Value
92.It Va si_code Ta Dv SI_TIMER
93.It Va si_value Ta
94the value stored in
95.Fa evp->sigev_value
96.It Va si_timerid Ta timer ID
97.It Va si_overrun Ta timer overrun count
98.It Va si_errno Ta
99If timer overrun is
100.Brq Dv DELAYTIMER_MAX ,
101an error code defined in
102.In errno.h
103.El
104.Pp
105If the
106.Fa evp
107argument is
108.Dv NULL ,
109the effect is as if the
110.Fa evp
111argument pointed to a
112.Vt sigevent
113structure with the
114.Va sigev_notify
115member having the value
116.Dv SIGEV_SIGNAL ,
117the
118.Va sigev_signo
119having a default signal number
120.Pq Dv SIGALRM ,
121and the
122.Va sigev_value
123member having
124the value of the timer ID.
125.Pp
126This implementation supports a
127.Fa clock_id
128of
129.Dv CLOCK_REALTIME ,
130.Dv CLOCK_TAI ,
131or
132.Dv CLOCK_MONOTONIC .
133.Pp
134If
135.Fa evp->sigev_notify
136is
137.Dv SIGEV_THREAD
138and
139.Fa sev->sigev_notify_attributes
140is not
141.Dv NULL ,
142if the attribute pointed to by
143.Fa sev->sigev_notify_attributes
144has
145a thread stack address specified by a call to
146.Fn pthread_attr_setstack
147or
148.Fn pthread_attr_setstackaddr ,
149the results are unspecified if the signal is generated more than once.
150.Sh RETURN VALUES
151If the call succeeds,
152.Fn timer_create
153returns zero and updates the location referenced by
154.Fa timerid
155to a
156.Vt timer_t ,
157which can be passed to the per-process timer calls.
158If an error
159occurs, the system call returns a value of \-1
160and the global variable
161.Va errno
162is set to indicate the
163error.
164The value of
165.Fa timerid
166is undefined if an error occurs.
167.Sh ERRORS
168The
169.Fn timer_create
170system call
171will fail if:
172.Bl -tag -width Er
173.It Bq Er EAGAIN
174The calling process has already created all of the timers it is allowed by
175this implementation.
176.It Bq Er EINVAL
177The specified clock ID is not supported.
178.It Bq Er EINVAL
179The specified asynchronous notification method is not supported.
180.It Bq Er EFAULT
181Any arguments point outside the allocated address space or there is a
182memory protection fault.
183.El
184.Sh SEE ALSO
185.Xr clock_getres 2 ,
186.Xr timer_delete 2 ,
187.Xr timer_getoverrun 2 ,
188.Xr sigevent 3 ,
189.Xr siginfo 3
190.Sh STANDARDS
191The
192.Fn timer_create
193system call conforms to
194.St -p1003.1-2004 .
195.Sh HISTORY
196Support for
197.Tn POSIX
198per-process timer first appeared in
199.Fx 7.0 .
200