.\" Copyright (c) 2006 by Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" 2008-06-24, mtk: added some details about where jiffies come into .\" play; added section on high-resolution timers. .\" .\" Japanese Version Copyright (c) 2006 Yuichi SATO .\" all rights reserved. .\" Translated 2006-07-23 by Yuichi SATO , LDP v2.36 .\" Updated 2007-05-04, Akihiro MOTOKI , LDP v2.44 .\" Updated 2008-08-10, Akihiro MOTOKI , LDP v3.05 .\" .TH TIME 7 2010-02-25 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O time \- overview of time and timers time \- 時間とタイマの概要 .\"O .SH DESCRIPTION .SH 説明 .\"O .SS "Real time and process time" .SS "実時間 (real time) とプロセス時間" .\"O .I "Real time" .\"O is defined as time measured from some fixed point, .\"O either from a standard point in the past .\"O (see the description of the Epoch and calendar time below), .\"O or from some point (e.g., the start) in the life of a process .\"O .RI ( "elapsed time" ). \fI実時間\fRは、特定の時点から計った時間と定義される。 特定の時点とは、過去の標準的な時点 (下記の紀元 (Epoch) とカレンダ時刻の説明を参照) や、 プロセスの一生における何らかの時点 (例えば、開始時) である .RI ( "経過時間" )。 .\"O .I "Process time" .\"O is defined as the amount of CPU time used by a process. .\"O This is sometimes divided into .\"O .I user .\"O and .\"O .I system .\"O components. \fIプロセス時間\fRは、プロセスによって使われた総 CPU 時間と定義される。 多くの場合、\fIユーザ\fR時間と\fIシステム\fR時間に分けられる。 .\"O User CPU time is the time spent executing code in user mode. .\"O System CPU time is the time spent by the kernel executing .\"O in system mode on behalf of the process (e.g., executing system calls). ユーザ CPU 時間は、コードをユーザモードで実行するのに使った時間である。 システム CPU 時間は、そのプロセスのために カーネルがシステムモードで実行するのに使った時間である (例えば、システムコールを実行するのに使った時間)。 .\"O The .\"O .BR time (1) .\"O command can be used to determine the amount of CPU time consumed .\"O during the execution of a program. .BR time (1) コマンドはプログラムの実行に費された総 CPU 時間を計るのに使用される。 .\"O A program can determine the amount of CPU time it has consumed using .\"O .BR times (2), .\"O .BR getrusage (2), .\"O or .\"O .BR clock (3). プログラムは、自身が費した総 CPU 時間を .BR times (2), .BR getrusage (2), .BR clock (3) を使って計ることができる。 .\"O .SS "The Hardware Clock" .SS ハードウェアクロック .\"O Most computers have a (battery-powered) hardware clock which the kernel .\"O reads at boot time in order to initialize the software clock. 多くのコンピュータが (電池で駆動される) ハードウェアクロックを持っている。 カーネルは起動時にソフトウェアクロックを初期化するために ハードウェアクロックを読み込む。 .\"O For further details, see .\"O .BR rtc (4) .\"O and .\"O .BR hwclock (8). より詳しい情報は、 .BR rtc (4) と .BR hwclock (8) を参照すること。 .\"O .SS "The Software Clock, HZ, and Jiffies" .\"Osato: 以下では jiffies は単数形 jiffy に統一している。 .SS "ソフトウェアクロック, HZ, Jiffy" .\"O The accuracy of various system calls that set timeouts, .\"O (e.g., .\"O .BR select (2), .\"O .BR sigtimedwait (2)) .\"O .\" semtimedop(), mq_timedwait(), io_getevents(), poll() are the same .\"O .\" futexes and thus sem_timedwait() seem to use high-res timers. .\"O and measure CPU time (e.g., .\"O .BR getrusage (2)) .\"O is limited by the resolution of the .\"O .IR "software clock" , .\"O a clock maintained by the kernel which measures time in .\"O .IR jiffies . .\"O The size of a jiffy is determined by the value of the kernel constant .\"O .IR HZ . タイムアウトを設定したり (例えば .BR select (2), .BR sigtimedwait (2))、 .\" semtimedop(), mq_timedwait(), io_getevents(), poll() は同じ futex であり、 .\" したがっって sem_timedwait() は高精度タイマを使用しているようである。 CPU 時間を計測したり (例えば .BR getrusage (2)) する様々なシステムコールの精度は .I ソフトウェアクロック の分解能 (resolution) に制限される。 ソフトウェアクロックとは、カーネルが管理する .I jiffy 単位で時間を計測するクロックのことである。 jiffy の大きさはカーネル定数 .I HZ の値で決定される。 .\"O The value of .\"O .I HZ .\"O varies across kernel versions and hardware platforms. .I HZ の値はカーネルのバージョンとハードウェアプラットフォームで異なる。 .\"O On i386 the situation is as follows: .\"O on kernels up to and including 2.4.x, HZ was 100, .\"O giving a jiffy value of 0.01 seconds; .\"O starting with 2.6.0, HZ was raised to 1000, giving a jiffy of .\"O 0.001 seconds. .\"O Since kernel 2.6.13, the HZ value is a kernel .\"O configuration parameter and can be 100, 250 (the default) or 1000, .\"O yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. i386 の場合は以下の通りである: 2.4.x とそれより前のカーネルでは、HZ は 100 であったので、 jiffy の値は 0.01 秒になっていた。 2.6.0 以降では、HZ は 1000 に増やされたので、jiffy の値は 0.001 秒である。 カーネル 2.6.13 以降では、HZ の値はカーネル設定パラメータになり、 100, 250 (デフォルト), 1000 という値にできる。 それぞれ jiffy の値は 0.01, 0.004, 0.001 秒になる。 .\"O Since kernel 2.6.20, a further frequency is available: .\"O 300, a number that divides evenly for the common video .\"O frame rates (PAL, 25 HZ; NTSC, 30 HZ). カーネル 2.6.20 以降では、300 も利用できるようになっている。 300 は一般的な映像フレームレートの公倍数である (PAL, 25HZ; NTSC, 30HZ)。 .\"O The .\"O .BR times (2) .\"O system call is a special case. .\"O It reports times with a granularity defined by the kernel constant .\"O .IR USER_HZ . .\"O Userspace applications can determine the value of this constant using .\"O .IR sysconf(_SC_CLK_TCK) . .BR times (2) システムコールは特殊なケースであり、 このシステムコールはカーネル定数 .I USER_HZ で定義された粒度で時間を報告する。 ユーザ空間のアプリケーションは .I sysconf(_SC_CLK_TCK) を使ってこの定数の値を知ることができる。 .\" glibc gets this info with a little help from the ELF loader; .\" see glibc elf/dl-support.c and kernel fs/binfmt_elf.c. .\" .\"O .SS "High-Resolution Timers" .SS "高精度タイマ" .\"O Before Linux 2.6.21, the accuracy of timer and sleep system calls .\"O (see below) was also limited by the size of the jiffy. Linux 2.6.21 より前では、タイマやスリープ関連のシステムコールの精度も jiffy のサイズにより制限されていた。 .\"O Since Linux 2.6.21, Linux supports high-resolution timers (HRTs), .\"O optionally configurable via .\"O .BR CONFIG_HIGH_RES_TIMERS . .\"O On a system that supports HRTs, the accuracy of sleep and timer .\"O system calls is no longer constrained by the jiffy, .\"O but instead can be as accurate as the hardware allows .\"O (microsecond accuracy is typical of modern hardware). .\"O You can determine whether high-resolution timers are supported by .\"O checking the resolution returned by a call to .\"O .BR clock_getres (2) .\"O or looking at the "resolution" entries in .\"O .IR /proc/timer_list . Linux 2.6.21 以降では、Linux は高精度タイマ (high-resolution timers; HRTs) をサポートしており、 .B CONFIG_HIGH_RES_TIMERS で制御できる。 高精度タイマをサポートしているシステムでは、タイマとスリープ関連のシステムコール の精度はもはや jiffy に制約されることはなく、 ハードウェアが許す限りの精度となる (最近のハードウェアではマイクロ秒単位の精度が一般的である)。 高精度タイマがサポートされているかは、 .BR clock_getres (2) を呼び出して分解能を確認するか、 .I /proc/timer_list 内の "resolution" エントリを参照するかで判断できる。 .\"O HRTs are not supported on all hardware architectures. .\"O (Support is provided on x86, arm, and powerpc, among others.) 高精度タイマはすべてのハードウェアアーキテクチャでサポートされている 訳ではない (対応しているアーキテクチャは x86, arm, powerpc である)。 .\"O .SS "The Epoch" .SS "紀元" .\"O Unix systems represent time in seconds since the .\"O .IR Epoch , .\"O 1970-01-01 00:00:00 +0000 (UTC). Unix システムは時刻を 紀元 (1970-01-01 00:00:00 +0000 (UTC)) からの秒数で表現する。 .\"O A program can determine the .\"O .I "calendar time" .\"O using .\"O .BR gettimeofday (2), .\"O which returns time (in seconds and microseconds) that have .\"O elapsed since the Epoch; プログラムは \fIカレンダ時刻\fR を .BR gettimeofday (2) を使って計ることができる。 この関数は紀元からの経過時間を (秒とマイクロ秒で) 返す。 .\"O .BR time (2) .\"O provides similar information, but only with accuracy to the .\"O nearest second. .\"O The system time can be changed using .\"O .BR settimeofday (2). .BR time (2) は同様の情報を提供するが、最も近い秒の精度しかない。 システム時刻は .BR settimeofday (2) で変更できる。 .\"O .SS "Broken-down time" .SS "要素別の時刻" .\"O Certain library functions use a structure of .\"O type .\"O .I tm .\"O to represent .\"O .IR "broken-down time" , .\"O which stores time value separated out into distinct components .\"O (year, month, day, hour, minute, second, etc.). ライブラリ関数の中には .I tm 型の構造体を使うものがある。 この構造体は\fI要素別の時刻\fRを表し、 時刻の値を別々の要素 (年・月・日・時・分・秒など) に分けて格納する。 .\"O This structure is described in .\"O .BR ctime (3), .\"O which also describes functions that convert between calendar time and .\"O broken-down time. この構造体は .BR ctime (3) に記述されており、カレンダ時刻を要素別の時刻に変換する 関数についても記述されている。 .\"O Functions for converting between broken-down time and printable .\"O string representations of the time are described in .\"O .BR ctime (3), .\"O .BR strftime (3), .\"O and .\"O .BR strptime (3). 要素別の時刻を表示可能な文字列に変換する関数については、 .BR ctime (3), .BR strftime (3), .BR strptime (3) に記述されている。 .\"O .SS "Sleeping and Setting Timers" .SS "タイマのスリープと設定" .\"O Various system calls and functions allow a program to sleep .\"O (suspend execution) for a specified period of time; see .\"O .BR nanosleep (2), .\"O .BR clock_nanosleep (2), .\"O and .\"O .BR sleep (3). 様々なシステムコールと関数により、指定された一定の時間、 プログラムはスリープ (実行を停止) することが可能である。 .BR nanosleep (2), .BR clock_nanosleep (2), .BR sleep (3) を参照すること。 .\"O Various system calls allow a process to set a timer that expires .\"O at some point in the future, and optionally at repeated intervals; .\"O see .\"O .BR alarm (2), .\"O .BR getitimer (2), .\"O .BR timerfd_create (2), .\"O and .\"O .BR timer_create (2). 様々なシステムコールにより、プロセスは将来のある時点で 有効期間が終了するタイマを設定できる。 またオプションとして繰り返し間隔が指定できるものもある。 .BR alarm (2), .BR getitimer (2), .BR timerfd_create (2), .BR timer_create (2) を参照すること。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR date (1), .BR time (1), .BR adjtimex (2), .BR alarm (2), .BR clock_gettime (2), .BR clock_nanosleep (2), .BR getitimer (2), .BR getrlimit (2), .BR getrusage (2), .BR gettimeofday (2), .BR nanosleep (2), .BR stat (2), .BR time (2), .BR timer_create (2), .BR timerfd_create (2), .BR times (2), .BR utime (2), .BR adjtime (3), .BR clock (3), .BR clock_getcpuclockid (3), .BR ctime (3), .BR pthread_getcpuclockid (3), .BR sleep (3), .BR strftime (3), .BR strptime (3), .BR timeradd (3), .BR usleep (3), .BR rtc (4), .BR hwclock (8)