]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/timer_create.2
_syscall.2, clock_getres.2, clone.2, copy_file_range.2, create_module.2, delete_modul...
[thirdparty/man-pages.git] / man2 / timer_create.2
CommitLineData
944f8a69
MK
1.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2.\" <mtk.manpages@gmail.com>
3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
944f8a69
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
07ee7db9 25.\"
f55a6d59 26.TH TIMER_CREATE 2 2017-07-13 Linux "Linux Programmer's Manual"
944f8a69
MK
27.SH NAME
28timer_create \- create a POSIX per-process timer
29.SH SYNOPSIS
30.nf
31.B #include <signal.h>
32.B #include <time.h>
dbfe9c70 33.PP
0d5f6a62 34.BI "int timer_create(clockid_t " clockid ", struct sigevent *" sevp ,
944f8a69
MK
35.BI " timer_t *" timerid );
36.fi
dbfe9c70 37.PP
702cbe15 38Link with \fI\-lrt\fP.
68e4db0a 39.PP
944f8a69
MK
40.in -4n
41Feature Test Macro Requirements for glibc (see
42.BR feature_test_macros (7)):
43.in
68e4db0a 44.PP
944f8a69 45.BR timer_create ():
98dbe7af 46_POSIX_C_SOURCE\ >=\ 199309L
944f8a69
MK
47.SH DESCRIPTION
48.BR timer_create ()
49creates a new per-process interval timer.
50The ID of the new timer is returned in the buffer pointed to by
51.IR timerid ,
b437fdd9 52which must be a non-null pointer.
944f8a69
MK
53This ID is unique within the process, until the timer is deleted.
54The new timer is initially disarmed.
55
56The
57.I clockid
58argument specifies the clock that the new timer uses to measure time.
59It can be specified as one of the following values:
60.TP
61.B CLOCK_REALTIME
62A settable system-wide real-time clock.
63.TP
64.B CLOCK_MONOTONIC
24b74457 65A nonsettable monotonically increasing clock that measures time
944f8a69
MK
66from some unspecified point in the past that does not change
67after system startup.
68.\" Note: the CLOCK_MONOTONIC_RAW clock added for clock_gettime()
69.\" in 2.6.28 is not supported for POSIX timers -- mtk, Feb 2009
70.TP
71.BR CLOCK_PROCESS_CPUTIME_ID " (since Linux 2.6.12)"
72A clock that measures (user and system) CPU time consumed by
73(all of the threads in) the calling process.
74.TP
75.BR CLOCK_THREAD_CPUTIME_ID " (since Linux 2.6.12)"
76A clock that measures (user and system) CPU time consumed by
77the calling thread.
78.\" The CLOCK_MONOTONIC_RAW that was added in 2.6.28 can't be used
79.\" to create a timer -- mtk, Feb 2009
39c97bde
MK
80.TP
81.BR CLOCK_BOOTTIME " (Since Linux 2.6.39)"
82.\" commit 70a08cca1227dc31c784ec930099a4417a06e7d0
83Like
84.BR CLOCK_MONOTONIC ,
85this is a monotonically increasing clock.
86However, whereas the
87.BR CLOCK_MONOTONIC
88clock does not measure the time while a system is suspended, the
89.BR CLOCK_BOOTTIME
90clock does include the time during which the system is suspended.
91This is useful for applications that need to be suspend-aware.
92.BR CLOCK_REALTIME
93is not suitable for such applications, since that clock is affected
94by discontinuous changes to the system clock.
8b047fe2
MK
95.TP
96.BR CLOCK_REALTIME_ALARM " (since Linux 3.0)"
97.\" commit 9a7adcf5c6dea63d2e47e6f6d2f7a6c9f48b9337
98This clock is like
99.BR CLOCK_REALTIME ,
100but will wake the system if it is suspended.
101The caller must have the
102.B CAP_WAKE_ALARM
103capability in order to set a timer against this clock.
104.TP
105.BR CLOCK_BOOTTIME_ALARM " (since Linux 3.0)"
106.\" commit 9a7adcf5c6dea63d2e47e6f6d2f7a6c9f48b9337
107This clock is like
108.BR CLOCK_BOOTTIME ,
109but will wake the system if it is suspended.
110The caller must have the
111.B CAP_WAKE_ALARM
112capability in order to set a timer against this clock.
944f8a69
MK
113.PP
114As well as the above values,
115.I clockid
116can be specified as the
117.I clockid
118returned by a call to
119.BR clock_getcpuclockid (3)
120or
121.BR pthread_getcpuclockid (3).
122
123The
0d5f6a62 124.I sevp
944f8a69
MK
125argument points to a
126.I sigevent
127structure that specifies how the caller
128should be notified when the timer expires.
0e39ed97
MK
129For the definition and general details of this structure, see
130.BR sigevent (7).
944f8a69 131
0e39ed97 132The
0d5f6a62 133.I sevp.sigev_notify
0e39ed97 134field can have the following values:
944f8a69
MK
135.TP
136.BR SIGEV_NONE
137Don't asynchronously notify when the timer expires.
138Progress of the timer can be monitored using
139.BR timer_gettime (2).
140.TP
141.BR SIGEV_SIGNAL
142Upon timer expiration, generate the signal
143.I sigev_signo
144for the process.
0e39ed97
MK
145See
146.BR sigevent (7)
147for general details.
148The
149.I si_code
150field of the
151.I siginfo_t
152structure will be set to
153.BR SI_TIMER .
944f8a69
MK
154At any point in time,
155at most one signal is queued to the process for a given timer; see
156.BR timer_getoverrun (2)
157for more details.
158.TP
159.BR SIGEV_THREAD
160Upon timer expiration, invoke
161.I sigev_notify_function
162as if it were the start function of a new thread.
0e39ed97
MK
163See
164.BR sigevent (7)
165for details.
944f8a69
MK
166.TP
167.BR SIGEV_THREAD_ID " (Linux-specific)"
168As for
169.BR SIGEV_SIGNAL ,
170but the signal is targeted at the thread whose ID is given in
171.IR sigev_notify_thread_id ,
172which must be a thread in the same process as the caller.
173The
174.IR sigev_notify_thread_id
175field specifies a kernel thread ID, that is, the value returned by
176.BR clone (2)
177or
178.BR gettid (2).
33a0ccb2 179This flag is intended only for use by threading libraries.
944f8a69
MK
180.PP
181Specifying
0d5f6a62 182.I sevp
944f8a69
MK
183as NULL is equivalent to specifying a pointer to a
184.I sigevent
185structure in which
186.I sigev_notify
187is
188.BR SIGEV_SIGNAL ,
189.I sigev_signo
190is
191.BR SIGALRM ,
192and
193.I sigev_value.sival_int
194is the timer ID.
195.SH RETURN VALUE
196On success,
197.BR timer_create ()
198returns 0, and the ID of the new timer is placed in
199.IR *timerid .
200On failure, \-1 is returned, and
201.I errno
202is set to indicate the error.
203.SH ERRORS
204.TP
205.B EAGAIN
206Temporary error during kernel allocation of timer structures.
207.TP
208.B EINVAL
209Clock ID,
210.IR sigev_notify ,
211.IR sigev_signo ,