.\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992 .\" and Copyright (c) 2002 Michael Kerrisk .\" .\" %%%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 .\" .\" 2004-11-16 -- mtk: the getrlimit.2 page, which formerly included .\" coverage of getrusage(2), has been split, so that the latter is .\" now covered in its own getrusage.2. For older details of change .\" history, etc., see getrlimit.2 .\" .\" Modified 2004-11-16, mtk, Noted that the nonconformance .\" when SIGCHLD is being ignored is fixed in 2.6.9. .\" 2008-02-22, Sripathi Kodi : Document RUSAGE_THREAD .\" 2008-05-25, mtk, clarify RUSAGE_CHILDREN + other clean-ups. .\" 2010-05-24, Mark Hills : Description of fields, .\" document ru_maxrss .\" 2010-05-24, mtk, enhanced description of various fields .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-02-22, HANATAKA Shinya .\" Updated and Modified 2001-06-02, Yuichi SATO .\" Updated and Modified 2001-08-18, Yuichi SATO .\" Updated and Modified 2002-08-25, Yuichi SATO .\" Updated and Modified 2004-01-17, Yuichi SATO .\" Updated and Modified 2004-12-30, Yuichi SATO .\" Updated and Modified 2005-09-06, Akihiro MOTOKI .\" Updated 2008-11-10, Akihiro MOTOKI, LDP v3.11 .\" Updated 2013-05-06, Akihiro MOTOKI .\" .TH GETRUSAGE 2 2014\-05\-10 Linux "Linux Programmer's Manual" .SH 名前 getrusage \- 資源の使用量を取得する .SH 書式 \fB#include \fP .br \fB#include \fP .sp \fBint getrusage(int \fP\fIwho\fP\fB, struct rusage *\fP\fIusage\fP\fB);\fP .SH 説明 .PP \fBgetrusage\fP() は \fIwho\fP の資源 (resource) の使用量を返す。 \fIwho\fP には以下のいずれか一つを指定できる。 .TP \fBRUSAGE_SELF\fP 呼び出したプロセスの資源使用量、 そのプロセス内の全スレッドが使用している資源の合計を返す。 .TP \fBRUSAGE_CHILDREN\fP 呼び出したプロセスの子プロセスのうち、 終了して待ち状態にある全プロセスが使用している資源使用量の統計を返す。 これらの統計情報には、孫プロセスやその子孫のプロセスのうち、 削除待ちのものが使用している資源も含まれる。 .TP \fBRUSAGE_THREAD\fP (Linux 2.6.26 以降) 呼び出したスレッドに関する資源使用量の統計を返す。 \fI\fP からこの定数の定義を得るためには、 ((\fIどの\fPヘッダーファイルをインクルードするよりも前に) 機能検査マクロ \fB_GNU_SOURCE\fP を定義しなければならない。 .PP 資源使用量は \fIusage\fP が指す構造体に格納されて返される。 構造体は以下の形式である。 .PP .in +4n .nf struct rusage { struct timeval ru_utime; /* 使用されたユーザー CPU 時間 */ struct timeval ru_stime; /* 使用されたシステム CPU 時間 */ long ru_maxrss; /* RAM 上に存在する仮想ページのサイズ (resident set size) の最大値 */ long ru_ixrss; /* 共有メモリーの合計サイズ */ long ru_idrss; /* 非共有データの合計サイズ */ long ru_isrss; /* 非共有スタックの合計サイズ */ long ru_minflt; /* ページの再利用 (ソフトページフォルト) */ long ru_majflt; /* ページフォールト (ハードページフォルト) */ long ru_nswap; /* スワップ */ long ru_inblock; /* ブロック入力操作 */ long ru_oublock; /* ブロック出力操作 */ long ru_msgsnd; /* 送信された IPC メッセージ */ long ru_msgrcv; /* 受信された IPC メッセージ */ long ru_nsignals; /* 受信されたシグナル */ long ru_nvcsw; /* 意図したコンテキスト切り替え */ long ru_nivcsw; /* 意図しないコンテキスト切り替え */ }; .fi .in .PP すべてのフィールドがサポートされているわけではない。 メンテナンスされていないフィールドには、 カーネルが 0 を設定する (メンテナンスされていないフィールドは、 他のシステムとの互換性のために提供されており、 いつか Linux でもサポートされるかもしれない)。 各フィールドの詳細は以下の通りである。 .TP \fIru_utime\fP ユーザーモードでの実行で消費された合計時間。 \fItimeval\fP 構造体 (秒とミリ秒) で表現される。 .TP \fIru_stime\fP カーネルモードでの実行で消費された合計時間。 \fItimeval\fP 構造体 (秒とミリ秒) で表現される。 .TP \fIru_maxrss\fP (Linux 2.6.32 以降) 使用された resident set size の最大値 (キロバイト単位)。 \fBRUSAGE_CHILDREN\fP の場合には、プロセスツリーの resident set size の最大値ではなく、 最も大きい子プロセスの resident set size となる。 .TP \fIru_ixrss\fP (メンテナンスされていない) .\" On some systems, .\" this is the integral of the text segment memory consumption, .\" expressed in kilobyte-seconds. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_idrss\fP (メンテナンスされていない) .\" On some systems, this is the integral of the data segment memory consumption, .\" expressed in kilobyte-seconds. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_isrss\fP (メンテナンスされていない) .\" On some systems, this is the integral of the stack memory consumption, .\" expressed in kilobyte-seconds. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_minflt\fP I/O 動作なしで発生したページフォルトの回数。 再割り当てを待っているページリストからページフレームを「回収」 (reclaim) することで、 I/O 動作を避けることができる。 .TP \fIru_majflt\fP I/O 動作を必要とするページフォルトの回数。 .TP \fIru_nswap\fP (メンテナンスされていない) .\" On some systems, this is the number of swaps out of physical memory. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_inblock\fP (Linux 2.6.22 以降) ファイルシステムが入力を実行する必要があった回数。 .TP \fIru_oublock\fP (Linux 2.6.22 以降) ファイルシステムが出力を実行する必要があった回数。 .TP \fIru_msgsnd\fP (メンテナンスされていない) .\" On FreeBSD 6.2, this appears to measure messages sent over sockets .\" On some systems, .\" this field records the number of messages sent over sockets. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_msgrcv\fP (メンテナンスされていない) .\" On FreeBSD 6.2, this appears to measure messages received over sockets .\" On some systems, .\" this field records the number of messages received over sockets. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_nsignals\fP (メンテナンスされていない) .\" On some systems, this field records the number of signals received. このフィールドは現在のところ Linux では未使用である。 .TP \fIru_nvcsw\fP (Linux 2.6 以降) 自分のタイムスライスが完了する前にプロセスが自発的にプロセッサを解放して行われたコンテキストスイッチの回数 (通常はリソースが利用可能になるのを待つために行われる)。 .TP \fIru_nivcsw\fP (Linux 2.6 以降) 優先度が自分より高いプロセッサが実行可能になったか、現在のプロセスが自分のタイムスライスを超過したことにより行われたコンテキストスイッチの回数。 .PP .SH 返り値 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。 .SH エラー .TP \fBEFAULT\fP \fIusage\fP がアクセス可能なアドレス空間の外を指している。 .TP \fBEINVAL\fP \fIwho\fP が無効である。 .SH 準拠 SVr4, 4.3BSD. POSIX.1\-2001 は \fBgetrusage\fP() を規定しているが、規定しているフィールドは \fIru_utime\fP と \fIru_stime\fP だけである。 \fBRUSAGE_THREAD\fP は Linux 固有である。 .SH 注意 \fBexecve\fP(2) の前後でリソース使用量の指標は保持される。 今日では \fI\fP をインクルードする必要はないが、 インクルードしておけば移植性が増す。 (実際 \fIstruct timeval\fP は \fI\fP で定義されている。) .PP .\" See the description of getrusage() in XSH. .\" A similar statement was also in SUSv2. 2.6.9 より前のバージョンの Linux カーネルでは、 \fBSIGCHLD\fP の処理が \fBSIG_IGN\fP に設定されていると、 子プロセスのリソース使用量が \fBRUSAGE_CHILDREN\fP で返される値に自動的に含められる。 しかし POSIX.1\-2001 では、これを明確に禁止している。 この準拠していなかった点は、Linux 2.6.9 以降で改正された。 .LP このページの最初で示した構造体の定義は 4.3BSD Reno のものである。 古いシステムでは、 \fBgetrusage\fP() と同様の目的を持つ関数 \fBvtimes\fP() が提供 されていた。後方互換性のため、glibc でも \fBvtimes\fP() を提供している。 全ての新しいアプリケーションでは \fBgetrusage\fP() を使用すべきである。 \fBproc\fP(5) にある \fI/proc/PID/stat\fP の説明も参照のこと。 .SH 関連項目 \fBclock_gettime\fP(2), \fBgetrlimit\fP(2), \fBtimes\fP(2), \fBwait\fP(2), \fBwait4\fP(2), \fBclock\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。