xref: /freebsd-14.2/lib/libc/sys/timer_create.2 (revision c8befdd5)
1.\" Copyright (c) 2005 David Xu <[email protected]>
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.\" $FreeBSD$
29.\"
30.Dd September 11, 2000
31.Dt TIMER_CREATE 2
32.Os
33.Sh NAME
34.Nm timer_create
35.Nd "create a per-process timer (REALTIME)"
36.Sh LIBRARY
37.Lb librt
38.Sh SYNOPSIS
39.In time.h
40.Ft int
41.Fo timer_create
42.Fa "clockid_t clockid" "struct sigevent *restrict evp"
43.Fa "timer_t *restrict timerid"
44.Fc
45.Sh DESCRIPTION
46The
47.Fn timer_create
48system call creates a per-process timer using the specified clock,
49.Fa clock_id ,
50as the timing base.
51The
52.Fn timer_create
53system call returns, in the location referenced by
54.Fa timerid ,
55a timer ID of type
56.Vt timer_t
57used to identify the timer in timer requests.
58This timer ID is unique within the calling process until the timer is deleted.
59The particular clock,
60.Fa clock_id ,
61is defined in
62.In time.h .
63The timer whose ID is returned is in a disarmed state upon return from
64.Fn timer_create .
65.Pp
66The
67.Fa evp
68argument, if
69.Pf non- Dv NULL ,
70points to a
71.Vt sigevent
72structure.
73This structure,
74allocated by the application, defines the asynchronous notification to occur
75when the timer expires.
76If the
77.Fa evp
78argument is
79.Dv NULL ,
80the effect is as if the
81.Fa evp
82argument pointed to a
83.Vt sigevent
84structure with the
85.Va sigev_notify
86member having the value
87.Dv SIGEV_SIGNAL ,
88the
89.Va sigev_signo
90having a default signal number, and the
91.Va sigev_value
92member having
93the value of the timer ID.
94.Pp
95The implementations supports a
96.Fa clock_id
97of
98.Dv CLOCK_REALTIME
99or
100.Dv CLOCK_MONOTONIC .
101.Pp
102If
103.Fa evp->sigev_sigev_notify
104is
105.Dv SIGEV_THREAD
106and
107.Fa sev->sigev_notify_attributes
108is not
109.Dv NULL ,
110if the attribute pointed to by
111.Fa sev->sigev_notify_attributes
112has
113a thread stack address specified by a call to
114.Fn pthread_attr_setstack
115or
116.Fn pthread_attr_setstackaddr ,
117the results are unspecified if the signal is generated more than once.
118.Sh RETURN VALUES
119If the call succeeds,
120.Fn timer_create
121returns zero and updates the location referenced by
122.Fa timerid
123to a
124.Vt timer_t ,
125which can be passed to the per-process timer calls.
126If an error
127occurs, the system call returns a value of \-1
128and the global variable
129.Va errno
130is set to indicate the
131error.
132The value of
133.Fa timerid
134is undefined if an error occurs.
135.Sh ERRORS
136The
137.Fn timer_create
138system call
139will fail if:
140.Bl -tag -width Er
141.It Bq Er EAGAIN
142The calling process has already created all of the timers it is allowed by
143this implementation.
144.It Bq Er EINVAL
145The specified clock ID is not supported.
146.It Bq Er EFAULT
147Any arguments point outside the allocated address space or there is a
148memory protection fault.
149.El
150.Sh SEE ALSO
151.Xr clock_getres 2 ,
152.Xr timer_delete 2 ,
153.Xr timer_getoverun 2 ,
154.Xr siginfo 3
155.Sh STANDARDS
156The
157.Fn timer_create
158system call conforms to
159.St -p1003.1-2004
160.Sh HISTORY
161Support for
162.Tn POSIX
163per-process timer first appeared in
164.Fx 7.0 .
165