OSDN Git Service

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