OSDN Git Service

Convert release and draft pages to UTF-8.
[linuxjm/jm.git] / manual / LDP_man-pages / release / man7 / time.7
1 .\" Copyright (c) 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
6 .\"
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.
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" 2008-06-24, mtk: added some details about where jiffies come into
24 .\"     play; added section on high-resolution timers.
25 .\"
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
31 .\"
32 .TH TIME 7 2010-02-25 "Linux" "Linux Programmer's Manual"
33 .SH 名前
34 time \- 時間とタイマの概要
35 .SH 説明
36 .SS "実時間 (real time) とプロセス時間"
37 \fI実時間\fRは、特定の時点から計った時間と定義される。
38 特定の時点とは、過去の標準的な時点
39 (下記の紀元 (Epoch) とカレンダ時刻の説明を参照) や、
40 プロセスの一生における何らかの時点 (例えば、開始時) である
41 .RI ( "経過時間" )。
42
43 \fIプロセス時間\fRは、プロセスによって使われた総 CPU 時間と定義される。
44 多くの場合、\fIユーザ\fR時間と\fIシステム\fR時間に分けられる。
45 ユーザ CPU 時間は、コードをユーザモードで実行するのに使った時間である。
46 システム CPU 時間は、そのプロセスのために
47 カーネルがシステムモードで実行するのに使った時間である
48 (例えば、システムコールを実行するのに使った時間)。
49 .BR time (1)
50 コマンドはプログラムの実行に費された総 CPU 時間を計るのに使用される。
51 プログラムは、自身が費した総 CPU 時間を
52 .BR times (2),
53 .BR getrusage (2),
54 .BR clock (3)
55 を使って計ることができる。
56 .SS ハードウェアクロック
57 多くのコンピュータが (電池で駆動される) ハードウェアクロックを持っている。
58 カーネルは起動時にソフトウェアクロックを初期化するために
59 ハードウェアクロックを読み込む。
60 より詳しい情報は、
61 .BR rtc (4)
62
63 .BR hwclock (8)
64 を参照すること。
65 .SS "ソフトウェアクロック, HZ, Jiffy"
66 タイムアウトを設定したり (例えば
67 .BR select (2),
68 .BR sigtimedwait (2))、
69 .\" semtimedop(), mq_timedwait(), io_getevents(), poll() は同じ futex であり、
70 .\" したがっって sem_timedwait() は高精度タイマを使用しているようである。
71 CPU 時間を計測したり (例えば
72 .BR getrusage (2)) する様々なシステムコールの精度は
73 .I ソフトウェアクロック
74 の分解能 (resolution) に制限される。
75 ソフトウェアクロックとは、カーネルが管理する
76 .I jiffy
77 単位で時間を計測するクロックのことである。
78 jiffy の大きさはカーネル定数
79 .I HZ
80 の値で決定される。
81
82 .I HZ
83 の値はカーネルのバージョンとハードウェアプラットフォームで異なる。
84 i386 の場合は以下の通りである:
85 2.4.x とそれより前のカーネルでは、HZ は 100 であったので、
86 jiffy の値は 0.01 秒になっていた。
87 2.6.0 以降では、HZ は 1000 に増やされたので、jiffy の値は 0.001 秒である。
88 カーネル 2.6.13 以降では、HZ の値はカーネル設定パラメータになり、
89 100, 250 (デフォルト), 1000 という値にできる。
90 それぞれ jiffy の値は 0.01, 0.004, 0.001 秒になる。
91 カーネル 2.6.20 以降では、300 も利用できるようになっている。
92 300 は一般的な映像フレームレートの公倍数である (PAL, 25HZ; NTSC, 30HZ)。
93
94 .BR times (2)
95 システムコールは特殊なケースであり、
96 このシステムコールはカーネル定数
97 .I USER_HZ
98 で定義された粒度で時間を報告する。
99 ユーザ空間のアプリケーションは
100 .I sysconf(_SC_CLK_TCK)
101 を使ってこの定数の値を知ることができる。
102 .\" glibc gets this info with a little help from the ELF loader;
103 .\" see glibc elf/dl-support.c and kernel fs/binfmt_elf.c.
104 .\"
105 .SS "高精度タイマ"
106 Linux 2.6.21 より前では、タイマやスリープ関連のシステムコールの精度も
107 jiffy のサイズにより制限されていた。
108
109 Linux 2.6.21 以降では、Linux は高精度タイマ (high-resolution timers; HRTs)
110 をサポートしており、
111 .B CONFIG_HIGH_RES_TIMERS
112 で制御できる。
113 高精度タイマをサポートしているシステムでは、タイマとスリープ関連のシステムコール
114 の精度はもはや jiffy に制約されることはなく、
115 ハードウェアが許す限りの精度となる
116 (最近のハードウェアではマイクロ秒単位の精度が一般的である)。
117 高精度タイマがサポートされているかは、
118 .BR clock_getres (2)
119 を呼び出して分解能を確認するか、
120 .I /proc/timer_list
121 内の "resolution" エントリを参照するかで判断できる。
122
123 高精度タイマはすべてのハードウェアアーキテクチャでサポートされている
124 訳ではない (対応しているアーキテクチャは x86, arm, powerpc である)。
125 .SS "紀元"
126 UNIX システムは時刻を
127 紀元 (1970-01-01 00:00:00 +0000 (UTC)) からの秒数で表現する。
128
129 プログラムは \fIカレンダ時刻\fR を
130 .BR gettimeofday (2)
131 を使って計ることができる。
132 この関数は紀元からの経過時間を (秒とマイクロ秒で) 返す。
133 .BR time (2)
134 は同様の情報を提供するが、最も近い秒の精度しかない。
135 システム時刻は
136 .BR settimeofday (2)
137 で変更できる。
138 .SS "要素別の時刻"
139 ライブラリ関数の中には
140 .I tm
141 型の構造体を使うものがある。
142 この構造体は\fI要素別の時刻\fRを表し、
143 時刻の値を別々の要素 (年・月・日・時・分・秒など) に分けて格納する。
144 この構造体は
145 .BR ctime (3)
146 に記述されており、カレンダ時刻を要素別の時刻に変換する
147 関数についても記述されている。
148 要素別の時刻を表示可能な文字列に変換する関数については、
149 .BR ctime (3),
150 .BR strftime (3),
151 .BR strptime (3)
152 に記述されている。
153 .SS "タイマのスリープと設定"
154 様々なシステムコールと関数により、指定された一定の時間、
155 プログラムはスリープ (実行を停止) することが可能である。
156 .BR nanosleep (2),
157 .BR clock_nanosleep (2),
158 .BR sleep (3)
159 を参照すること。
160
161 様々なシステムコールにより、プロセスは将来のある時点で
162 有効期間が終了するタイマを設定できる。
163 またオプションとして繰り返し間隔が指定できるものもある。
164 .BR alarm (2),
165 .BR getitimer (2),
166 .BR timerfd_create (2),
167 .BR timer_create (2)
168 を参照すること。
169 .SH 関連項目
170 .BR date (1),
171 .BR time (1),
172 .BR adjtimex (2),
173 .BR alarm (2),
174 .BR clock_gettime (2),
175 .BR clock_nanosleep (2),
176 .BR getitimer (2),
177 .BR getrlimit (2),
178 .BR getrusage (2),
179 .BR gettimeofday (2),
180 .BR nanosleep (2),
181 .BR stat (2),
182 .BR time (2),
183 .BR timer_create (2),
184 .BR timerfd_create (2),
185 .BR times (2),
186 .BR utime (2),
187 .BR adjtime (3),
188 .BR clock (3),
189 .BR clock_getcpuclockid (3),
190 .BR ctime (3),
191 .BR pthread_getcpuclockid (3),
192 .BR sleep (3),
193 .BR strftime (3),
194 .BR strptime (3),
195 .BR timeradd (3),
196 .BR usleep (3),
197 .BR rtc (4),
198 .BR hwclock (8)