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