1 .\" Copyright (c) 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 2008-06-24, mtk: added some details about where jiffies come into
24 .\" play; added section on high-resolution timers.
26 .\" Japanese Version Copyright (c) 2006 Yuichi SATO
27 .\" all rights reserved.
28 .\" Translated 2006-07-23 by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v2.36
29 .\" Updated 2007-05-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.44
30 .\" Updated 2008-08-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
32 .TH TIME 7 2010-02-25 "Linux" "Linux Programmer's Manual"
35 .\"O time \- overview of time and timers
36 time \- »þ´Ö¤È¥¿¥¤¥Þ¤Î³µÍ×
39 .\"O .SS "Real time and process time"
40 .SS "¼Â»þ´Ö (real time) ¤È¥×¥í¥»¥¹»þ´Ö"
42 .\"O is defined as time measured from some fixed point,
43 .\"O either from a standard point in the past
44 .\"O (see the description of the Epoch and calendar time below),
45 .\"O or from some point (e.g., the start) in the life of a process
46 .\"O .RI ( "elapsed time" ).
47 \fI¼Â»þ´Ö\fR¤Ï¡¢ÆÃÄê¤Î»þÅÀ¤«¤é·×¤Ã¤¿»þ´Ö¤ÈÄêµÁ¤µ¤ì¤ë¡£
48 ÆÃÄê¤Î»þÅÀ¤È¤Ï¡¢²áµî¤Îɸ½àŪ¤Ê»þÅÀ
49 (²¼µ¤Îµª¸µ (Epoch) ¤È¥«¥ì¥ó¥À»þ¹ï¤ÎÀâÌÀ¤ò»²¾È) ¤ä¡¢
50 ¥×¥í¥»¥¹¤Î°ìÀ¸¤Ë¤ª¤±¤ë²¿¤é¤«¤Î»þÅÀ (Î㤨¤Ð¡¢³«»Ï»þ) ¤Ç¤¢¤ë
53 .\"O .I "Process time"
54 .\"O is defined as the amount of CPU time used by a process.
55 .\"O This is sometimes divided into
60 \fI¥×¥í¥»¥¹»þ´Ö\fR¤Ï¡¢¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æ»È¤ï¤ì¤¿Áí CPU »þ´Ö¤ÈÄêµÁ¤µ¤ì¤ë¡£
61 ¿¤¯¤Î¾ì¹ç¡¢\fI¥æ¡¼¥¶\fR»þ´Ö¤È\fI¥·¥¹¥Æ¥à\fR»þ´Ö¤Ëʬ¤±¤é¤ì¤ë¡£
62 .\"O User CPU time is the time spent executing code in user mode.
63 .\"O System CPU time is the time spent by the kernel executing
64 .\"O in system mode on behalf of the process (e.g., executing system calls).
65 ¥æ¡¼¥¶ CPU »þ´Ö¤Ï¡¢¥³¡¼¥É¤ò¥æ¡¼¥¶¥â¡¼¥É¤Ç¼Â¹Ô¤¹¤ë¤Î¤Ë»È¤Ã¤¿»þ´Ö¤Ç¤¢¤ë¡£
66 ¥·¥¹¥Æ¥à CPU »þ´Ö¤Ï¡¢¤½¤Î¥×¥í¥»¥¹¤Î¤¿¤á¤Ë
67 ¥«¡¼¥Í¥ë¤¬¥·¥¹¥Æ¥à¥â¡¼¥É¤Ç¼Â¹Ô¤¹¤ë¤Î¤Ë»È¤Ã¤¿»þ´Ö¤Ç¤¢¤ë
68 (Î㤨¤Ð¡¢¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¼Â¹Ô¤¹¤ë¤Î¤Ë»È¤Ã¤¿»þ´Ö)¡£
71 .\"O command can be used to determine the amount of CPU time consumed
72 .\"O during the execution of a program.
74 ¥³¥Þ¥ó¥É¤Ï¥×¥í¥°¥é¥à¤Î¼Â¹Ô¤ËÈñ¤µ¤ì¤¿Áí CPU »þ´Ö¤ò·×¤ë¤Î¤Ë»ÈÍѤµ¤ì¤ë¡£
75 .\"O A program can determine the amount of CPU time it has consumed using
77 .\"O .BR getrusage (2),
80 ¥×¥í¥°¥é¥à¤Ï¡¢¼«¿È¤¬Èñ¤·¤¿Áí CPU »þ´Ö¤ò
84 ¤ò»È¤Ã¤Æ·×¤ë¤³¤È¤¬¤Ç¤¤ë¡£
85 .\"O .SS "The Hardware Clock"
86 .SS ¥Ï¡¼¥É¥¦¥§¥¢¥¯¥í¥Ã¥¯
87 .\"O Most computers have a (battery-powered) hardware clock which the kernel
88 .\"O reads at boot time in order to initialize the software clock.
89 ¿¤¯¤Î¥³¥ó¥Ô¥å¡¼¥¿¤¬ (ÅÅÃӤǶîÆ°¤µ¤ì¤ë) ¥Ï¡¼¥É¥¦¥§¥¢¥¯¥í¥Ã¥¯¤ò»ý¤Ã¤Æ¤¤¤ë¡£
90 ¥«¡¼¥Í¥ë¤Ïµ¯Æ°»þ¤Ë¥½¥Õ¥È¥¦¥§¥¢¥¯¥í¥Ã¥¯¤ò½é´ü²½¤¹¤ë¤¿¤á¤Ë
91 ¥Ï¡¼¥É¥¦¥§¥¢¥¯¥í¥Ã¥¯¤òÆɤ߹þ¤à¡£
92 .\"O For further details, see
101 .\"O .SS "The Software Clock, HZ, and Jiffies"
102 .\"Osato: °Ê²¼¤Ç¤Ï jiffies ¤Ïñ¿ô·Á jiffy ¤ËÅý°ì¤·¤Æ¤¤¤ë¡£
103 .SS "¥½¥Õ¥È¥¦¥§¥¢¥¯¥í¥Ã¥¯, HZ, Jiffy"
104 .\"O The accuracy of various system calls that set timeouts,
107 .\"O .BR sigtimedwait (2))
108 .\"O .\" semtimedop(), mq_timedwait(), io_getevents(), poll() are the same
109 .\"O .\" futexes and thus sem_timedwait() seem to use high-res timers.
110 .\"O and measure CPU time (e.g.,
111 .\"O .BR getrusage (2))
112 .\"O is limited by the resolution of the
113 .\"O .IR "software clock" ,
114 .\"O a clock maintained by the kernel which measures time in
116 .\"O The size of a jiffy is determined by the value of the kernel constant
118 ¥¿¥¤¥à¥¢¥¦¥È¤òÀßÄꤷ¤¿¤ê (Î㤨¤Ð
120 .BR sigtimedwait (2))¡¢
121 .\" semtimedop(), mq_timedwait(), io_getevents(), poll() ¤ÏƱ¤¸ futex ¤Ç¤¢¤ê¡¢
122 .\" ¤·¤¿¤¬¤Ã¤Ã¤Æ sem_timedwait() ¤Ï¹âÀºÅÙ¥¿¥¤¥Þ¤ò»ÈÍѤ·¤Æ¤¤¤ë¤è¤¦¤Ç¤¢¤ë¡£
123 CPU »þ´Ö¤ò·×¬¤·¤¿¤ê (Î㤨¤Ð
124 .BR getrusage (2)) ¤¹¤ëÍÍ¡¹¤Ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÎÀºÅÙ¤Ï
125 .I ¥½¥Õ¥È¥¦¥§¥¢¥¯¥í¥Ã¥¯
126 ¤Îʬ²òǽ (resolution) ¤ËÀ©¸Â¤µ¤ì¤ë¡£
127 ¥½¥Õ¥È¥¦¥§¥¢¥¯¥í¥Ã¥¯¤È¤Ï¡¢¥«¡¼¥Í¥ë¤¬´ÉÍý¤¹¤ë
129 ñ°Ì¤Ç»þ´Ö¤ò·×¬¤¹¤ë¥¯¥í¥Ã¥¯¤Î¤³¤È¤Ç¤¢¤ë¡£
130 jiffy ¤ÎÂ礤µ¤Ï¥«¡¼¥Í¥ëÄê¿ô
136 .\"O varies across kernel versions and hardware platforms.
138 ¤ÎÃͤϥ«¡¼¥Í¥ë¤Î¥Ð¡¼¥¸¥ç¥ó¤È¥Ï¡¼¥É¥¦¥§¥¢¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç°Û¤Ê¤ë¡£
139 .\"O On i386 the situation is as follows:
140 .\"O on kernels up to and including 2.4.x, HZ was 100,
141 .\"O giving a jiffy value of 0.01 seconds;
142 .\"O starting with 2.6.0, HZ was raised to 1000, giving a jiffy of
144 .\"O Since kernel 2.6.13, the HZ value is a kernel
145 .\"O configuration parameter and can be 100, 250 (the default) or 1000,
146 .\"O yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds.
147 i386 ¤Î¾ì¹ç¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë:
148 2.4.x ¤È¤½¤ì¤è¤êÁ°¤Î¥«¡¼¥Í¥ë¤Ç¤Ï¡¢HZ ¤Ï 100 ¤Ç¤¢¤Ã¤¿¤Î¤Ç¡¢
149 jiffy ¤ÎÃÍ¤Ï 0.01 ÉäˤʤäƤ¤¤¿¡£
150 2.6.0 °Ê¹ß¤Ç¤Ï¡¢HZ ¤Ï 1000 ¤ËÁý¤ä¤µ¤ì¤¿¤Î¤Ç¡¢jiffy ¤ÎÃÍ¤Ï 0.001 ÉäǤ¢¤ë¡£
151 ¥«¡¼¥Í¥ë 2.6.13 °Ê¹ß¤Ç¤Ï¡¢HZ ¤ÎÃͤϥ«¡¼¥Í¥ëÀßÄê¥Ñ¥é¥á¡¼¥¿¤Ë¤Ê¤ê¡¢
152 100, 250 (¥Ç¥Õ¥©¥ë¥È), 1000 ¤È¤¤¤¦ÃͤˤǤ¤ë¡£
153 ¤½¤ì¤¾¤ì jiffy ¤ÎÃÍ¤Ï 0.01, 0.004, 0.001 Éäˤʤ롣
154 .\"O Since kernel 2.6.20, a further frequency is available:
155 .\"O 300, a number that divides evenly for the common video
156 .\"O frame rates (PAL, 25 HZ; NTSC, 30 HZ).
157 ¥«¡¼¥Í¥ë 2.6.20 °Ê¹ß¤Ç¤Ï¡¢300 ¤âÍøÍѤǤ¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
158 300 ¤Ï°ìÈÌŪ¤Ê±ÇÁü¥Õ¥ì¡¼¥à¥ì¡¼¥È¤Î¸øÇÜ¿ô¤Ç¤¢¤ë (PAL, 25HZ; NTSC, 30HZ)¡£
162 .\"O system call is a special case.
163 .\"O It reports times with a granularity defined by the kernel constant
165 .\"O Userspace applications can determine the value of this constant using
166 .\"O .IR sysconf(_SC_CLK_TCK) .
168 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÏÆüì¤Ê¥±¡¼¥¹¤Ç¤¢¤ê¡¢
169 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¥«¡¼¥Í¥ëÄê¿ô
171 ¤ÇÄêµÁ¤µ¤ì¤¿Î³Å٤ǻþ´Ö¤òÊó¹ð¤¹¤ë¡£
172 ¥æ¡¼¥¶¶õ´Ö¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï
173 .I sysconf(_SC_CLK_TCK)
174 ¤ò»È¤Ã¤Æ¤³¤ÎÄê¿ô¤ÎÃͤòÃΤ뤳¤È¤¬¤Ç¤¤ë¡£
175 .\" glibc gets this info with a little help from the ELF loader;
176 .\" see glibc elf/dl-support.c and kernel fs/binfmt_elf.c.
178 .\"O .SS "High-Resolution Timers"
180 .\"O Before Linux 2.6.21, the accuracy of timer and sleep system calls
181 .\"O (see below) was also limited by the size of the jiffy.
182 Linux 2.6.21 ¤è¤êÁ°¤Ç¤Ï¡¢¥¿¥¤¥Þ¤ä¥¹¥ê¡¼¥×´ØÏ¢¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÎÀºÅÙ¤â
183 jiffy ¤Î¥µ¥¤¥º¤Ë¤è¤êÀ©¸Â¤µ¤ì¤Æ¤¤¤¿¡£
185 .\"O Since Linux 2.6.21, Linux supports high-resolution timers (HRTs),
186 .\"O optionally configurable via
187 .\"O .BR CONFIG_HIGH_RES_TIMERS .
188 .\"O On a system that supports HRTs, the accuracy of sleep and timer
189 .\"O system calls is no longer constrained by the jiffy,
190 .\"O but instead can be as accurate as the hardware allows
191 .\"O (microsecond accuracy is typical of modern hardware).
192 .\"O You can determine whether high-resolution timers are supported by
193 .\"O checking the resolution returned by a call to
194 .\"O .BR clock_getres (2)
195 .\"O or looking at the "resolution" entries in
196 .\"O .IR /proc/timer_list .
197 Linux 2.6.21 °Ê¹ß¤Ç¤Ï¡¢Linux ¤Ï¹âÀºÅÙ¥¿¥¤¥Þ (high-resolution timers; HRTs)
199 .B CONFIG_HIGH_RES_TIMERS
201 ¹âÀºÅÙ¥¿¥¤¥Þ¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¥¿¥¤¥Þ¤È¥¹¥ê¡¼¥×´ØÏ¢¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë
202 ¤ÎÀºÅ٤Ϥâ¤Ï¤ä jiffy ¤ËÀ©Ì󤵤ì¤ë¤³¤È¤Ï¤Ê¤¯¡¢
203 ¥Ï¡¼¥É¥¦¥§¥¢¤¬µö¤¹¸Â¤ê¤ÎÀºÅ٤Ȥʤë
204 (ºÇ¶á¤Î¥Ï¡¼¥É¥¦¥§¥¢¤Ç¤Ï¥Þ¥¤¥¯¥íÉÃñ°Ì¤ÎÀºÅÙ¤¬°ìÈÌŪ¤Ç¤¢¤ë)¡£
205 ¹âÀºÅÙ¥¿¥¤¥Þ¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤«¤Ï¡¢
207 ¤ò¸Æ¤Ó½Ð¤·¤Æʬ²òǽ¤ò³Îǧ¤¹¤ë¤«¡¢
209 Æâ¤Î "resolution" ¥¨¥ó¥È¥ê¤ò»²¾È¤¹¤ë¤«¤ÇȽÃǤǤ¤ë¡£
211 .\"O HRTs are not supported on all hardware architectures.
212 .\"O (Support is provided on x86, arm, and powerpc, among others.)
213 ¹âÀºÅÙ¥¿¥¤¥Þ¤Ï¤¹¤Ù¤Æ¤Î¥Ï¡¼¥É¥¦¥§¥¢¥¢¡¼¥¥Æ¥¯¥Á¥ã¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë
214 Ìõ¤Ç¤Ï¤Ê¤¤ (Âбþ¤·¤Æ¤¤¤ë¥¢¡¼¥¥Æ¥¯¥Á¥ã¤Ï x86, arm, powerpc ¤Ç¤¢¤ë)¡£
217 .\"O Unix systems represent time in seconds since the
219 .\"O 1970-01-01 00:00:00 +0000 (UTC).
220 Unix ¥·¥¹¥Æ¥à¤Ï»þ¹ï¤ò
221 µª¸µ (1970-01-01 00:00:00 +0000 (UTC)) ¤«¤é¤ÎÉÿô¤Çɽ¸½¤¹¤ë¡£
223 .\"O A program can determine the
224 .\"O .I "calendar time"
226 .\"O .BR gettimeofday (2),
227 .\"O which returns time (in seconds and microseconds) that have
228 .\"O elapsed since the Epoch;
229 ¥×¥í¥°¥é¥à¤Ï \fI¥«¥ì¥ó¥À»þ¹ï\fR ¤ò
231 ¤ò»È¤Ã¤Æ·×¤ë¤³¤È¤¬¤Ç¤¤ë¡£
232 ¤³¤Î´Ø¿ô¤Ïµª¸µ¤«¤é¤Î·Ð²á»þ´Ö¤ò (Éäȥޥ¤¥¯¥íÉäÇ) ÊÖ¤¹¡£
234 .\"O provides similar information, but only with accuracy to the
236 .\"O The system time can be changed using
237 .\"O .BR settimeofday (2).
239 ¤ÏƱÍͤξðÊó¤òÄ󶡤¹¤ë¤¬¡¢ºÇ¤â¶á¤¤ÉäÎÀºÅÙ¤·¤«¤Ê¤¤¡£
243 .\"O .SS "Broken-down time"
245 .\"O Certain library functions use a structure of
249 .\"O .IR "broken-down time" ,
250 .\"O which stores time value separated out into distinct components
251 .\"O (year, month, day, hour, minute, second, etc.).
252 ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤ÎÃæ¤Ë¤Ï
254 ·¿¤Î¹½Â¤ÂΤò»È¤¦¤â¤Î¤¬¤¢¤ë¡£
255 ¤³¤Î¹½Â¤ÂΤÏ\fIÍ×ÁÇÊ̤λþ¹ï\fR¤òɽ¤·¡¢
256 »þ¹ï¤ÎÃͤòÊÌ¡¹¤ÎÍ×ÁÇ (ǯ¡¦·î¡¦Æü¡¦»þ¡¦Ê¬¡¦ÉäʤÉ) ¤Ëʬ¤±¤Æ³ÊǼ¤¹¤ë¡£
257 .\"O This structure is described in
259 .\"O which also describes functions that convert between calendar time and
260 .\"O broken-down time.
263 ¤Ëµ½Ò¤µ¤ì¤Æ¤ª¤ê¡¢¥«¥ì¥ó¥À»þ¹ï¤òÍ×ÁÇÊ̤λþ¹ï¤ËÊÑ´¹¤¹¤ë
264 ´Ø¿ô¤Ë¤Ä¤¤¤Æ¤âµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£
265 .\"O Functions for converting between broken-down time and printable
266 .\"O string representations of the time are described in
268 .\"O .BR strftime (3),
270 .\"O .BR strptime (3).
271 Í×ÁÇÊ̤λþ¹ï¤òɽ¼¨²Äǽ¤Êʸ»úÎó¤ËÊÑ´¹¤¹¤ë´Ø¿ô¤Ë¤Ä¤¤¤Æ¤Ï¡¢
276 .\"O .SS "Sleeping and Setting Timers"
277 .SS "¥¿¥¤¥Þ¤Î¥¹¥ê¡¼¥×¤ÈÀßÄê"
278 .\"O Various system calls and functions allow a program to sleep
279 .\"O (suspend execution) for a specified period of time; see
280 .\"O .BR nanosleep (2),
281 .\"O .BR clock_nanosleep (2),
284 ÍÍ¡¹¤Ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤È´Ø¿ô¤Ë¤è¤ê¡¢»ØÄꤵ¤ì¤¿°ìÄê¤Î»þ´Ö¡¢
285 ¥×¥í¥°¥é¥à¤Ï¥¹¥ê¡¼¥× (¼Â¹Ô¤òÄä»ß) ¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¢¤ë¡£
287 .BR clock_nanosleep (2),
291 .\"O Various system calls allow a process to set a timer that expires
292 .\"O at some point in the future, and optionally at repeated intervals;
295 .\"O .BR getitimer (2),
296 .\"O .BR timerfd_create (2),
298 .\"O .BR timer_create (2).
299 ÍÍ¡¹¤Ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ë¤è¤ê¡¢¥×¥í¥»¥¹¤Ï¾Íè¤Î¤¢¤ë»þÅÀ¤Ç
300 ͸ú´ü´Ö¤¬½ªÎ»¤¹¤ë¥¿¥¤¥Þ¤òÀßÄê¤Ç¤¤ë¡£
301 ¤Þ¤¿¥ª¥×¥·¥ç¥ó¤È¤·¤Æ·«¤êÊÖ¤·´Ö³Ö¤¬»ØÄê¤Ç¤¤ë¤â¤Î¤â¤¢¤ë¡£
304 .BR timerfd_create (2),
313 .BR clock_gettime (2),
314 .BR clock_nanosleep (2),
318 .BR gettimeofday (2),
322 .BR timer_create (2),
323 .BR timerfd_create (2),
328 .BR clock_getcpuclockid (3),
330 .BR pthread_getcpuclockid (3),