OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[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 .\" 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 2009-02-20 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 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 ()
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 returns the previous interval of the timer (in
145 .IR old_value->it_interval )
146 and the amount of time until the timer
147 would previously have next expired (in
148 .IR old_value->it_value ).
149
150 .BR timer_gettime ()
151 returns the time until next expiration, and the interval,
152 for the timer specified by
153 .IR timerid ,
154 in the buffer pointed to by
155 .IR curr_value .
156 The time remaining until the next timer expiration is returned in
157 .IR curr_value->it_value ;
158 this is always a relative value, regardless of whether the
159 .BR TIMER_ABSTIME
160 flag was used when arming the timer.
161 If the value returned in
162 .IR curr_value->it_value
163 is zero, then the timer is currently disarmed.
164 The timer interval is returned in
165 .IR curr_value->it_interval .
166 If the value returned in
167 .IR curr_value->it_interval
168 is zero, then this is a "one-shot" timer.
169 .SH RETURN VALUE
170 On success,
171 .BR timer_settime ()
172 and
173 .BR timer_gettime ()
174 return 0.
175 On error, \-1 is returned, and
176 .I errno
177 is set to indicate the error.
178 .SH ERRORS
179 These functions may fail with the following errors:
180 .TP
181 .B EFAULT
182 .IR new_value ,
183 .IR old_value ,
184 or
185 .I curr_value
186 is not a valid pointer.
187 .TP
188 .B EINVAL
189 .I timerid
190 is invalid.
191 .\" FIXME . eventually: invalid value in flags
192 .PP
193 .BR timer_settime ()
194 may fail with the following errors:
195 .TP
196 .B EINVAL
197 .I new_value.it_value
198 is negative; or
199 .I new_value.it_value.tv_nsec
200 is negative or greater than 999,999,999.
201 .SH VERSIONS
202 These system calls are available since Linux 2.6.
203 .SH CONFORMING TO
204 POSIX.1-2001
205 .SH EXAMPLE
206 See
207 .BR timer_create (2).
208 .SH SEE ALSO
209 .BR timer_create (2),
210 .BR timer_settime (2),
211 .BR timer_getoverrun (2),
212 .BR time (7)