.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992 .\" .\" %%%LICENSE_START(VERBATIM) .\" 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. .\" %%%LICENSE_END .\" .\" Modified by Michael Haardt (michael@moria.de) .\" Modified Sat Jul 24 14:29:17 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified 961203 and 001211 and 010326 by aeb@cwi.nl .\" Modified 001213 by Michael Haardt (michael@moria.de) .\" Modified 13 Jun 02, Michael Kerrisk .\" Added note on nonstandard behavior when SIGCHLD is ignored. .\" Modified 2004-11-16, mtk, Noted that the nonconformance when .\" SIGCHLD is being ignored is fixed in 2.6.9; other minor changes .\" Modified 2004-12-08, mtk, in 2.6 times() return value changed .\" 2005-04-13, mtk .\" Added notes on nonstandard behavior: Linux allows 'buf' to .\" be NULL, but POSIX.1 doesn't specify this and it's nonportable. .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1996 Satoshi Nozawa .\" all rights reserved. .\" Translated 1996-06-25, Satoshi I. Nozawa .\" Modified 1997-12-14, HANATAKA Shinya .\" Updated 2001-02-16, Kentaro Shirakata .\" Updated 2001-04-10, Kentaro Shirakata .\" Updated 2001-05-21, Kentaro Shirakata .\" Updated 2002-10-21, Kentaro Shirakata .\" Updated 2005-02-24, Akihiro MOTOKI .\" Updated 2005-04-20, Kentaro Shirakata .\" Updated 2008-02-12, Akihiro MOTOKI , LDP v2.77 .\" .TH TIMES 2 2012\-10\-22 Linux "Linux Programmer's Manual" .SH 名前 times \- プロセス時間を取得する .SH 書式 \fB#include \fP .sp \fBclock_t times(struct tms *\fP\fIbuf\fP\fB);\fP .SH 説明 \fBtimes\fP() は現在のプロセス時間を \fIbuf\fP が指している \fBstruct tms\fP に格納する。 \fIstruct tms\fP は \fI\fP で以下のように定義されている: .sp .in +4n .nf struct tms { clock_t tms_utime; /* user time */ clock_t tms_stime; /* system time */ clock_t tms_cutime; /* user time of children */ clock_t tms_cstime; /* system time of children */ }; .fi .in .LP \fItms_utime\fP フィールドは、呼び出したプロセスが命令を実行するのに消費した CPU 時間である。 \fItms_stime\fP フィールドは、呼び出したプロセスのために実行されたタスクで、 システムが消費した CPU 時間である。 \fItms_cutime\fP フィールドは、 終了を待っている全ての子プロセスの \fItms_utime\fP と \fItms_cutime\fP の合計である。 \fItms_cstime\fP フィールドは、 終了を待っている全ての子プロセスの \fItms_stime\fP と \fItms_cstime\fP の合計である。 .LP 終了する子(及びその子孫)プロセスの時間は \fBwait\fP(2) や \fBwaitpid\fP(2) がプロセス ID を返した瞬間に加算される。 つまり、子がまだ終了を待っていない状態では 孫プロセスの時間は決して現れない。 .LP 全ての時間はクロック数で返される。 .SH 返り値 \fBtimes\fP() は過去のある時点から経過したクロック数 (clock tick) を返す。 この返り値は \fIclock_t\fP 型が取り得る範囲からオーバーフローするかもしれない。 エラーの場合、\fI(clock_t)\ \-1\fP が返され、 \fIerrno\fP が適切に設定される。 .SH エラー .TP \fBEFAULT\fP \fItms\fP がプロセスのアドレス空間の外を指している。 .SH 準拠 SVr4, 4.3BSD, POSIX.1\-2001. .SH 注意 一秒あたりのクロック数は以下で得ることができる。 .in +4n sysconf(_SC_CLK_TCK); .in .PP POSIX.1\-1996 では、\fBCLK_TCK\fP シンボル (\fI\fP で定義されている) は古いものであると記述されている。 今ではこれは古いものである。 .PP .\" See the description of times() in XSH, which says: .\" The times of a terminated child process are included... when wait() .\" or waitpid() returns the process ID of this terminated child. Linux 2.6.9 より前のバージョンでは、 \fBSIGCHLD\fP を \fBSIG_IGN\fP に設定すると 終了した子プロセスの回数は 自動的に \fItms_cstime\fP と \fItms_cutime\fP フィールドに含まれる。 しかし、POSIX.1\-2001 では、この動作は呼び出し元が \fBwait\fP(2) 関数群で子プロセスを待った場合にのみ起きるべきだとしている。 標準とは異なるこの動作は Linux 2.6.9 以降で修正されている。 Linux では、 \fIbuf\fP 引数に NULL を指定することができ、その場合は \fBtimes\fP() は単に関数の結果を返す。 しかし、POSIX はこの振る舞いは規定されておらず、 その他のほとんどの UNIX 実装は \fIbuf\fP の値として非 NULL の値を要求する。 .LP \fBclock\fP(3) も \fIclock_t\fP 型の値を返すが、この値は \fBtimes\fP() で使用されるクロック tick 数ではなく、 \fBCLOCKS_PER_SEC\fP が単位である点に注意すること。 .\" .PP .\" On older systems the number of clock ticks per second is given .\" by the variable HZ. Linux では、 \fBtimes\fP() の返り値を計算する起点となる「過去の任意の時点」は、カーネルのバージョン により異なる。 Linux 2.4 以前では、この時点はシステムが起動した瞬間である。 Linux 2.6 以降では、この時点はシステム起動時刻の \fI(2^32/HZ) \- 300\fP (および 4億2900万) 秒前である。 このようにカーネルバージョン (や UNIX の実装) により異なることと、 返り値が \fIclock_t\fP の範囲をオーバーフローする可能性があるという事実を考慮すると、 移植性が必要なアプリケーションではこの値を使うのは避けるのが賢明であろう。 経過時間を測りたい場合には、代わりに \fBclock_gettime\fP(2) を使用すること。 .SS 歴史 SVr1\-3 では \fIlong\fP を返し、構造体のメンバに \fItime_t\fP 型を使っていたが、紀元からの秒数ではなくクロック数を格納していた。 V7 では構造体のメンバに \fIlong\fP 型を使っていた。まだ \fItime_t\fP 型がなかったからである。 .SH バグ .\" The problem is that a syscall return of -4095 to -1 .\" is interpreted by glibc as an error, and the wrapper converts .\" the return value to -1. .\" http://marc.info/?l=linux-kernel&m=119447727031225&w=2 .\" "compat_sys_times() bogus until jiffies >= 0" .\" November 2007 いくつかのアーキテクチャー (特に i386) における Linux のシステムコールの慣習の 制限により、Linux 2.6 では起動直後は (41秒と) タイムウィンドウが小さく、 \fBtimes\fP() がエラーが起こったことを示す \-1 を間違って返すことがある。 返り値 が \fIclock_t\fP が格納可能な最大値を超過した際にも同じ問題が起こり得る。 .SH 関連項目 \fBtime\fP(1), \fBgetrusage\fP(2), \fBwait\fP(2), \fBclock\fP(3), \fBsysconf\fP(3), \fBtime\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。