1 .\" Copyright 7/93 by Darren Senn <sinster@scintilla.santa-clara.ca.us>
2 .\" Based on a similar page Copyright 1992 by Rick Faith
3 .\" May be freely distributed
4 .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
5 .\" 2005-04-06 mtk, Matthias Lang <matthias@corelatus.se>
6 .\" Noted MAX_SEC_IN_JIFFIES ceiling
8 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
9 .\" all rights reserved.
10 .\" Translated 1997-02-22, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
11 .\" Updated 2005-04-23, Kentaro Shirakata <argrath@ub32.org>
12 .\" Updated 2005-09-11, Kentaro Shirakata <argrath@ub32.org>
13 .\" Updated 2006-07-23, Kentaro Shirakata <argrath@ub32.org>
14 .\" Updated 2007-10-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
15 .\" Updated 2009-04-13, Akihiro MOTOKI, LDP v3.20
17 .\" WORD: timer ¥¿¥¤¥Þ¡¼
18 .\" WORD: jiffies jiffy
20 .TH GETITIMER 2 2009-03-15 "Linux" "Linux Programmer's Manual"
22 getitimer, setitimer \- ¥¤¥ó¥¿¡¼¥Ð¥ë¡¦¥¿¥¤¥Þ¡¼¤ÎÃͤò¼èÆÀ¤Þ¤¿¤ÏÀßÄꤹ¤ë
25 .B #include <sys/time.h>
27 .BI "int getitimer(int " which ", struct itimerval *" curr_value );
29 .BI "int setitimer(int " which ", const struct itimerval *" new_value ,
30 .BI " struct itimerval *" old_value );
33 .\"O The system provides each process with three interval timers, each decrementing
34 .\"O in a distinct time domain.
35 .\"O When any timer expires, a signal is sent to the
36 .\"O process, and the timer (potentially) restarts.
37 ¥·¥¹¥Æ¥à¤Ï 1 ¸Ä¤Î¥×¥í¥»¥¹¤Ë¤Ä¤ 3 ¸Ä¤Î¥¤¥ó¥¿¡¼¥Ð¥ë¡¦¥¿¥¤¥Þ¡¼¤òÄ󶡤¹¤ë¡£
38 ¤½¤ì¤¾¤ì¤Î¥¿¥¤¥Þ¡¼¤ÏÊÌ¡¹¤Î»þ´ÖÎΰè¤Ç¸º¾¯¤¹¤ë¡£
39 ¤É¤Î¥¿¥¤¥Þ¡¼¤âËþλ¤¹¤ë¤È¥×¥í¥»¥¹¤Ë¥·¥°¥Ê¥ë¤¬Á÷¤é¤ì¡¢
40 ¥¿¥¤¥Þ¡¼¤Ï (ÀßÄê¤Ë¤è¤Ã¤Æ¤Ï) ºÆ¤Ó³«»Ï¤µ¤ì¤ë¡£
43 .\"O decrements in real time, and delivers
47 ¼Â»þ´Ö (real time) ¤Ç¸º¾¯¤·¡¢Ëþλ¤¹¤ë¤È
51 .\"O .B ITIMER_VIRTUAL
52 .\"O decrements only when the process is executing, and delivers
56 ¥×¥í¥»¥¹¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë´Ö¤Î¤ß¸º¾¯¤·¡¢Ëþλ¤¹¤ë¤È
61 .\"O decrements both when the process executes and when the system is executing
62 .\"O on behalf of the process.
64 .\"O .BR ITIMER_VIRTUAL ,
65 .\"O this timer is usually used to profile the time spent by the
66 .\"O application in user and kernel space.
68 .\"O is delivered upon expiration.
70 ¥×¥í¥»¥¹¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤Æ¡¢
71 ¤«¤Ä¥·¥¹¥Æ¥à¤¬¤½¤Î¥×¥í¥»¥¹¤Î¤¿¤á¤Ë½èÍý¤ò¹Ô¤Ê¤Ã¤Æ¤¤¤ë´Ö¤Ë¸º¾¯¤¹¤ë¡£
72 ¿¤¯¤Î¾ì¹ç¡¢¤³¤Î¥¿¥¤¥Þ¡¼¤Ï
74 ¤ÈÁȤ߹ç¤ï¤µ¤ì¤Æ¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¥«¡¼¥Í¥ë¶õ´Ö¤È¥æ¡¼¥¶¡¼¶õ´Ö¤Ç
75 ¤É¤ì¤À¤±¤Î»þ´Ö¤ò²á¤´¤·¤¿¤«¤ò¥×¥í¥Õ¥¡¥¤¥ë¤¹¤ë¤Î¤Ë»ÈÍѤµ¤ì¤ë¡£
80 .\"O Timer values are defined by the following structures:
81 ¥¿¥¤¥Þ¡¼¤ÎÃͤϰʲ¼¤Î¹½Â¤ÂΤˤè¤Ã¤ÆÄêµÁ¤µ¤ì¤ë:
87 struct timeval it_interval; /* next value */
88 struct timeval it_value; /* current value */
92 long tv_sec; /* seconds */
93 long tv_usec; /* microseconds */
100 .\"O .BR getitimer ()
101 .\"O fills the structure pointed to by
103 .\"O with the current setting for the timer specified by
106 .\"O .BR ITIMER_REAL ,
107 .\"O .BR ITIMER_VIRTUAL ,
109 .\"O .BR ITIMER_PROF ).
117 ¤Î¤É¤ì¤«) ¤Î¸½ºß¤ÎÀßÄê¤ò¡¢
119 ¤Ç»ØÄꤵ¤ì¤¿¹½Â¤ÂΤ˳ÊǼ¤¹¤ë¡£
122 .\"O is set to the amount of time remaining on the timer, or zero if the timer
126 .\"O is set to the reset value.
128 Í×ÁǤˤϥ¿¥¤¥Þ¡¼¤Î»Ä¤ê»þ´Ö¤¬ÀßÄꤵ¤ì¤ë¡£¥¿¥¤¥Þ¡¼¤¬¥ª¥Õ¤Î¾ì¹ç¤Ï
129 ¥¼¥í¤¬ÀßÄꤵ¤ì¤ë¡£Æ±ÍͤË
131 ¤Ë¤Ï½é´üÃͤ¬ÀßÄꤵ¤ì¤ë¡£
134 .\"O .BR setitimer ()
135 .\"O sets the specified timer to the value in
138 ´Ø¿ô¤Ï»ØÄꤵ¤ì¤¿¥¿¥¤¥Þ¡¼¤Ë
143 .\"O is non-NULL, the old value of the timer is stored there.
145 ¤¬ NULL °Ê³°¤Î¾ì¹ç¡¢¥¿¥¤¥Þ¡¼¤Î¸Å¤¤Ãͤ¬
149 .\"O Timers decrement from
151 .\"O to zero, generate a signal, and reset to
152 .\"O .IR it_interval .
155 ¤«¤é¥¼¥í¤Ø¸þ¤±¤Æ¸º¤Ã¤Æ¤¤¤¡¢¥·¥°¥Ê¥ë¤òÀ¸À®¤·¡¢
158 .\"O A timer which is set to zero
160 .\"O is zero or the timer expires and
163 ¥¿¥¤¥Þ¡¼¤¬¥¼¥í¤ËÀßÄꤵ¤ì¤¿¾ì¹ç
165 ¤¬¥¼¥í¤«¡¢¥¿¥¤¥Þ¡¼¤¬Ëþλ¤·¤¿»þ¤Ë
167 ¤¬¥¼¥í¤Î¾ì¹ç) ¤ÏÄä»ß¤¹¤ë¡£
173 .\"O are significant in determining the duration of a timer.
178 ¤ÎξÊý¤Ë¤è¤ê·èÄꤵ¤ì¤ë¡£
180 .\"O Timers will never expire before the requested time,
181 .\"O but may expire some (short) time afterwards, which depends
182 .\"O on the system timer resolution and on the system load; see
184 .\"O (But see BUGS below.)
185 .\"O Upon expiration, a signal will be generated and the timer reset.
186 .\"O If the timer expires while the process is active (always true for
187 .\"O .BR ITIMER_VIRTUAL )
188 .\"O the signal will be delivered immediately when generated.
190 .\"O delivery will be offset by a small time dependent on the system loading.
191 Í׵ᤷ¤¿»þ´Ö¤¬¤¯¤ëÁ°¤Ë¥¿¥¤¥Þ¡¼¤¬Ëþλ¤¹¤ë¤³¤È¤Ï¤Ê¤¤¤¬¡¢
192 µÕ¤Ë¤¢¤ë (û¤¤) »þ´Ö¤À¤±Ëþ뤬ÃÙ¤ì¤ë¤³¤È¤Ï¤¢¤ë¡£
193 ¤É¤ì¤À¤±ÃÙ¤ì¤ë¤«¤Ï¥·¥¹¥Æ¥à¤Î»þ´Öʬ²òǽ¤È¥·¥¹¥Æ¥à¤ÎÉé²Ù¤Ë°Í¸¤¹¤ë
195 »²¾È; ⤷¡¢¥Ð¥°¤Î¹à¤â»²¾È¤Î¤³¤È)¡£
196 ¥¿¥¤¥Þ¡¼¤¬Ëþλ¤¹¤ë¤È¥·¥°¥Ê¥ë¤¬À¸À®¤µ¤ì¡¢¥¿¥¤¥Þ¡¼¤Ï½é´ü²½¤µ¤ì¤ë¡£
197 ¥×¥í¥»¥¹¤¬¥¢¥¯¥Æ¥£¥Ö¤Ê»þ
199 ¤Î¾ì¹ç¤Ë¤Ï¾ï¤Ë¤½¤¦¤Ç¤¢¤ë) ¤Ë¥¿¥¤¥Þ¡¼¤¬Ëþλ¤·¤¿¾ì¹ç¡¢À¸À®¤µ¤ì¤¿¥·¥°¥Ê¥ë¤Ï
200 ¤¹¤°¤ËÇÛÁ÷¤µ¤ì¤ë¡£¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¡¢¥·¥¹¥Æ¥à¤ÎÉé²Ù¤Ë¤è¤ê¾¯¤·¤Î»þ´Ö¤À¤±
203 .\"O On success, zero is returned.
204 .\"O On error, \-1 is returned, and
206 .\"O is set appropriately.
207 À®¸ù¤·¤¿¾ì¹ç¤Ï¥¼¥í¤¬Ê֤롣¥¨¥é¡¼¤Î¾ì¹ç¤Ï \-1 ¤¬Ê֤ꡢ
217 .\"O is not valid a pointer.
221 ¤¬Í¸ú¤Ê¥Ý¥¤¥ó¥¿¡¼¤Ç¤Ê¤¤¡£
226 .\"O .BR ITIMER_REAL ,
227 .\"O .BR ITIMER_VIRTUAL ,
229 .\"O .BR ITIMER_PROF ;
230 .\"O or (since Linux 2.6.22) one of the
232 .\"O fields in the structure pointed to by
234 .\"O contains a value outside the range 0 to 999999.
241 ¤Þ¤¿¤Ï (Linux 2.6.22 °Ê¹ß¤Ç)
245 ¥Õ¥£¡¼¥ë¥É¤Î°ì¤Ä¤¬ 0 °Ê¾å 999999 °Ê²¼¤ÎÈϰϤËÆþ¤é¤Ê¤¤ÃͤǤ¢¤ë¡£
246 .\"O .SH "CONFORMING TO"
248 .\"O POSIX.1-2001, SVr4, 4.4BSD (this call first appeared in 4.2BSD).
249 POSIX.1-2001, SVr4, 4.4BSD (¤³¤Î¥³¡¼¥ë¤Ï 4.2BSD ¤Ç»Ï¤á¤Æ¸½¤ï¤ì¤¿).
250 .\"O POSIX.1-2008 marks
251 .\"O .BR getitimer ()
253 .\"O .BR setitimer ()
254 .\"O obsolete, recommending the use of the POSIX timers API
255 .\"O .RB ( timer_gettime (2),
256 .\"O .BR timer_settime (2),
262 ¤ÏÇÑ»ßͽÄê¤È¤µ¤ì¤Æ¤ª¤ê¡¢
263 Âå¤ï¤ê¤Ë POSIX ¥¿¥¤¥Þ¡¼ API
264 .RB ( timer_gettime (2),
265 .BR timer_settime (2)
266 ¤Ê¤É) ¤ò»È¤¦¤³¤È¤¬¿ä¾©¤µ¤ì¤Æ¤¤¤ë¡£
269 .\"O A child created via
271 .\"O does not inherit its parent's interval timers.
272 .\"O Interval timers are preserved across an
275 ¤ÇºîÀ®¤µ¤ì¤¿»Ò¥×¥í¥»¥¹¤Ï¡¢
276 ¿Æ¥×¥í¥»¥¹¤Î¥¤¥ó¥¿¡¼¥Ð¥ë¡¦¥¿¥¤¥Þ¡¼¤ò·Ñ¾µ¤·¤Ê¤¤¡£
278 ¤ÎÁ°¸å¤Ç¤Ï¥¤¥ó¥¿¡¼¥Ð¥ë¡¦¥¿¥¤¥Þ¡¼¤ÏÊݸ¤µ¤ì¤ë¡£
280 .\"O POSIX.1 leaves the
281 .\"O interaction between
283 .\"O and the three interfaces
295 ¤È¤¤¤¦ 3 ¤Ä¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤È¤ÎÁê¸ß¤Î±Æ¶Á¤Ë¤Ä¤¤¤Æ¤Ïµ¬Äꤷ¤Æ¤¤¤Ê¤¤¡£
298 .\"O The generation and delivery of a signal are distinct, and
299 .\"O only one instance of each of the signals listed above may be pending
301 .\"O Under very heavy loading, an
303 .\"O timer may expire before the signal from a previous expiration
304 .\"O has been delivered.
305 .\"O The second signal in such an event will be lost.
306 ¥·¥°¥Ê¥ë¤ÎÀ¸À®¤ÈÇÛÁ÷¤ÏÊ̸ĤΤâ¤Î¤Ç¤¢¤ê¡¢
307 Á°½Ò¤Î¥·¥°¥Ê¥ë¤Î¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æ°ì¤Ä¤À¤±¤¬¥×¥í¥»¥¹¤Î¤¿¤á¤Ë
309 Èó¾ï¤Ë½Å¤¤Éé²Ù¤Î²¼¤Ç¤Ï¡¢
311 ¥¿¥¤¥Þ¡¼¤Ç¤Ï¡¢»þ´ÖÀÚ¤ì¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿°ì¤ÄÁ°¤Î¥·¥°¥Ê¥ë¤¬ÇÛÁ÷¤µ¤ì¤ëÁ°¤Ë¡¢
312 ¼¡¤Î»þ´ÖÀڤ줬µ¯¤³¤ë¾ì¹ç¤¬¤¢¤ë¡£
313 ¤½¤Î¤è¤¦¤Ê¾ì¹ç¡¢ 2 ¸Ä¤á¤Î¥¤¥Ù¥ó¥È¤ËÂФ¹¤ë¥·¥°¥Ê¥ë¤Ï¼º¤ï¤ì¤Æ¤·¤Þ¤¦¡£
315 .\"O On Linux kernels before 2.6.16, timer values are represented in jiffies.
316 ¥Ð¡¼¥¸¥ç¥ó 2.6.16 ¤è¤êÁ°¤Î Linux ¥«¡¼¥Í¥ë¤Ç¤Ï¡¢
317 ¥¿¥¤¥Þ¡¼¤ÎÃÍ¤Ï jiffy ¤Çɽ¸½¤µ¤ì¤ë¡£
318 .\"O If a request is made set a timer with a value whose jiffies
319 .\"O representation exceeds
320 .\"O .B MAX_SEC_IN_JIFFIES
322 .\"O .IR include/linux/jiffies.h ),
323 .\"O then the timer is silently truncated to this ceiling value.
324 .\"O On Linux/i386 (where, since Linux 2.6.13,
325 .\"O the default jiffy is 0.004 seconds),
326 .\"O this means that the ceiling value for a timer is
327 .\"O approximately 99.42 days.
329 .RI ( include/linux/jiffies.h
331 .B MAX_SEC_IN_JIFFIES
332 ¤ò±Û¤¨¤ëÃͤò¥¿¥¤¥Þ¡¼¤ËÀßÄꤷ¤è¤¦¤È¤¹¤ë¤â¤Î¤Î¾ì¹ç¡¢
333 ¥¿¥¤¥Þ¡¼¤Ï°ÅÌۤˤ³¤Î¾å¸ÂÃͤËÀÚ¤êµÍ¤á¤é¤ì¤ë¡£
334 Linux/i386 ¤Î¾ì¹ç (Linux 2.6.13 °Ê¹ß¤Ç¤Ï jiffy ¤Ï 0.004 ÉÃ) ¤Î¾ì¹ç¡¢
335 ¤³¤ì¤Ï¥¿¥¤¥Þ¡¼¤Î¾å¸ÂÃͤ¬¤ª¤è¤½ 99.42 Æü¤Ë¤Ê¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
336 .\"O Since Linux 2.6.16,
337 .\"O the kernel uses a different internal representation for times,
338 .\"O and this ceiling is removed.
339 Linux 2.6.16 °Ê¹ß¤Ç¤Ï¡¢¥«¡¼¥Í¥ë¤Ï»þ´Ö¤Ë´Ø¤¹¤ëÆâÉôɽ¸½¤È¤·¤Æ
340 °Û¤Ê¤ëɽ¸½¤ò»È¤¦¤è¤¦¤Ë¤Ê¤Ã¤Æ¤ª¤ê¡¢¤³¤Î¾å¸Â¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£
342 .\"O On certain systems (including i386),
343 .\"O Linux kernels before version 2.6.12 have a bug which will produce
344 .\"O premature timer expirations of up to one jiffy under some circumstances.
345 .\"O This bug is fixed in kernel 2.6.12.
346 (i386 ¤ò´Þ¤à) ¤¤¤¯¤Ä¤«¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
347 ¥Ð¡¼¥¸¥ç¥ó 2.6.12 °ÊÁ°¤Î Linux ¥«¡¼¥Í¥ë¤Ï
348 ¤¢¤ë¼ï¤Î¾õ¶·¤Ç¤Ï 1 jiffy Á᤯¥¿¥¤¥Þ¡¼¤¬½ªÎ»¤·¤Æ¤·¤Þ¤¦¤È¤¤¤¦¥Ð¥°¤¬¤¢¤Ã¤¿¡£
349 ¤³¤Î¥Ð¥°¤Ï¥«¡¼¥Í¥ë 2.6.12 ¤Ç½¤Àµ¤µ¤ì¤¿¡£
350 .\" 4 Jul 2005: It looks like this bug may remain in 2.4.x.
351 .\" http://lkml.org/lkml/2005/7/1/165
353 .\"O POSIX.1-2001 says that
354 .\"O .BR setitimer ()
355 .\"O should fail if a
357 .\"O value is specified that is outside of the range 0 to 999999.
358 .\"O However, in kernels up to and including 2.6.21,
359 .\"O Linux does not give an error, but instead silently
360 .\"O adjusts the corresponding seconds value for the timer.
365 ¤ÎÃͤ¬ 0 ¤«¤é 999999 ¤ÎÈϰϳ°¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¼ºÇÔ¤¹¤ë¤Ù¤¤À¤È¤·¤Æ¤¤¤ë¡£
366 ¤·¤«¤·¡¢2.6.21 °ÊÁ°¤Î¥«¡¼¥Í¥ë¤Î Linux ¤Ç¤Ï¥¨¥é¡¼¤Ë¤Ê¤é¤º¡¢
367 Âбþ¤¹¤ëÉÿô¤Îʬ¤À¤±¤½¤Î¥¿¥¤¥Þ¡¼¤ÎÉäÎÃͤ¬°ÅÌÛ¤ËÄ´À°¤µ¤ì¤ë¡£
368 .\"O From kernel 2.6.22 onwards,
369 .\"O this nonconformance has been repaired:
372 .\"O value results in an
375 ¥«¡¼¥Í¥ë 2.6.22 °Ê¹ß¤Ç¤Ï¡¢¤³¤Îɸ½àÈó½àµò¤ÎÆ°ºî¤Ï½¤Àµ¤µ¤ì¡¢
377 ¤ÎÃͤ¬ÉÔŬÀڤʾì¹ç¤Ë¤Ï
380 .\" Bugzilla report 25 Apr 2006:
381 .\" http://bugzilla.kernel.org/show_bug.cgi?id=6443
382 .\" "setitimer() should reject noncanonical arguments"
385 .BR gettimeofday (2),
388 .BR timer_create (2),
389 .BR timerfd_create (2),