]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/timer_settime.2
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man2 / timer_settime.2
1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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.
24 .\" %%%LICENSE_END
25 .TH TIMER_SETTIME 2 2012-10-15 Linux "Linux Programmer's Manual"
26 .SH NAME
27 timer_settime, timer_gettime \- arm/disarm and fetch
28 state of POSIX per-process timer
29 .SH SYNOPSIS
30 .nf
31 .B #include <time.h>
32
33 .BI "int timer_settime(timer_t " timerid ", int " flags ,
34 .BI " const struct itimerspec *" new_value ,
35 .BI " struct itimerspec * " old_value );
36 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
37 .fi
38
39 Link with \fI\-lrt\fP.
40 .sp
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .sp
46 .BR timer_settime (),
47 .BR timer_gettime ():
48 _POSIX_C_SOURCE\ >=\ 199309L
49 .SH DESCRIPTION
50 .BR timer_settime ()
51 arms or disarms the timer identified by
52 .IR timerid .
53 The
54 .I new_value
55 argument is pointer to an
56 .I itimerspec
57 structure that specifies the new initial value and
58 the new interval for the timer.
59 The
60 .I itimerspec
61 structure is defined as follows:
62
63 .in +4n
64 .nf
65 struct timespec {
66 time_t tv_sec; /* Seconds */
67 long tv_nsec; /* Nanoseconds */
68 };
69
70 struct itimerspec {
71 struct timespec it_interval; /* Timer interval */
72 struct timespec it_value; /* Initial expiration */
73 };
74 .fi
75 .in
76
77 Each of the substructures of the
78 .I itimerspec
79 structure is a
80 .I timespec
81 structure that allows a time value to be specified
82 in seconds and nanoseconds.
83 These time values are measured according to the clock
84 that was specified when the timer was created by
85 .BR timer_create (2)
86
87 If
88 .I new_value->it_value
89 specifies a nonzero value (i.e., either subfield is nonzero), then
90 .BR timer_settime ()
91 arms (starts) the timer,
92 setting it to initially expire at the given time.
93 (If the timer was already armed,
94 then the previous settings are overwritten.)
95 If
96 .I new_value->it_value
97 specifies a zero value
98 (i.e., both subfields are zero),
99 then the timer is disarmed.
100
101 The
102 .I new_value->it_interval
103 field specifies the period of the timer, in seconds and nanoseconds.
104 If this field is nonzero, then each time that an armed timer expires,
105 the timer is reloaded from the value specified in
106 .IR new_value->it_interval .
107 If
108 .I new_value->it_interval
109 specifies a zero value
110 then the timer expires just once, at the time specified by
111 .IR it_value .
112
113 By default, the initial expiration time specified in
114 .I new_value->it_value
115 is interpreted relative to the current time on the timer's
116 clock at the time of the call.
117 This can be modified by specifying
118 .B TIMER_ABSTIME
119 in
120 .IR flags ,
121 in which case
122 .I new_value->it_value
123 is interpreted as an absolute value as measured on the timer's clock;
124 that is, the timer will expire when the clock value reaches the
125 value specified by
126 .IR new_value->it_value .
127 If the specified absolute time has already passed,
128 then the timer expires immediately,
129 and the overrun count (see
130 .BR timer_getoverrun (2))
131 will be set correctly.
132 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
133
134 If the value of the
135 .B CLOCK_REALTIME
136 clock is adjusted while an absolute timer based on that clock is armed,
137 then the expiration of the timer will be appropriately adjusted.
138 Adjustments to the
139 .B CLOCK_REALTIME
140 clock have no effect on relative timers based on that clock.
141 .\" Similar remarks might apply with respect to process and thread CPU time
142 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
143
144 If
145 .I old_value
146 is not NULL, then it points to a buffer
147 that is used to return the previous interval of the timer (in
148 .IR old_value->it_interval )
149 and the amount of time until the timer
150 would previously have next expired (in
151 .IR old_value->it_value ).
152
153 .BR timer_gettime ()
154 returns the time until next expiration, and the interval,
155 for the timer specified by
156 .IR timerid ,
157 in the buffer pointed to by
158 .IR curr_value .
159 The time remaining until the next timer expiration is returned in
160 .IR curr_value->it_value ;
161 this is always a relative value, regardless of whether the
162 .BR TIMER_ABSTIME
163 flag was used when arming the timer.
164 If the value returned in
165 .IR curr_value->it_value
166 is zero, then the timer is currently disarmed.
167 The timer interval is returned in
168 .IR curr_value->it_interval .
169 If the value returned in
170 .IR curr_value->it_interval
171 is zero, then this is a "one-shot" timer.
172 .SH RETURN VALUE
173 On success,
174 .BR timer_settime ()
175 and
176 .BR timer_gettime ()
177 return 0.
178 On error, \-1 is returned, and
179 .I errno
180 is set to indicate the error.
181 .SH ERRORS
182 These functions may fail with the following errors:
183 .TP
184 .B EFAULT
185 .IR new_value ,
186 .IR old_value ,
187 or
188 .I curr_value
189 is not a valid pointer.
190 .TP
191 .B EINVAL
192 .I timerid
193 is invalid.
194 .\" FIXME . eventually: invalid value in flags
195 .PP
196 .BR timer_settime ()
197 may fail with the following errors:
198 .TP
199 .B EINVAL
200 .I new_value.it_value
201 is negative; or
202 .I new_value.it_value.tv_nsec
203 is negative or greater than 999,999,999.
204 .SH VERSIONS
205 These system calls are available since Linux 2.6.
206 .SH CONFORMING TO
207 POSIX.1-2001.
208 .SH EXAMPLE
209 See
210 .BR timer_create (2).
211 .SH SEE ALSO
212 .BR timer_create (2),
213 .BR timer_getoverrun (2),
214 .BR time (7)