getrusageのヘルプ・マニュアル
日本語 英語
getrusage --help
man getrusage
GETRUSAGE(2) Linux Programmer’s Manual GETRUSAGE(2)
名前
getrusage - 資源の使用量を取得する
書式
#include
#include
int getrusage(int who, struct rusage *usage);
説明
getrusage() は who の資源 (resource) の使用量を返す。 who には以下のい
ずれか一つを指定できる。
RUSAGE_SELF
呼び出したプロセスの資源使用量、そのプロセス内の全スレッドが使用
している資源の合計を返す。
前者は呼び出したプロセスのリソース使用量を要求し、後者は呼び出し
たプロセスの子供のうち終了して待ち状態にあるプロセスの使用量を要
求する。
RUSAGE_CHILDREN
呼び出したプロセスの子プロセスのうち、終了して待ち状態にある全プ
ロセスが使用している資源使用量の統計を返す。これらの統計情報には
、孫プロセスやその子孫のプロセスのうち、削除待ちのものが使用して
いる資源も含まれる。
RUSAGE_THREAD (Linux 2.6.26 以降)
呼び出したスレッドに関する資源使用量の統計を返す。
資源使用量は usage が指す構造体に格納されて返される。構造体は以下の形式
である。
struct rusage {
struct timeval ru_utime; /* 使用されたユーザー時間 */
struct timeval ru_stime; /* 使用されたシステム時間 */
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; /* 送信されたメッセージ */
long ru_msgrcv; /* 受信されたメッセージ */
long ru_nsignals; /* 受信されたシグナル */
long ru_nvcsw; /* 意図したコンテキスト切り替え */
long ru_nivcsw; /* 意図しないコンテキスト切り替え */
};
返り値
成 功した場合は 0 が返される。エラーの場合は -1 が返され、 errno に適切
な値が設定される。
エラー
EFAULT usage がアクセス可能なアドレス空間の外を指している。
EINVAL who が無効である。
準拠
SVr4, 4.3BSD. POSIX.1-2001 は getrusage() を規定しているが、規定してい
るフィールドは ru_utime と ru_stime だけである。
RUSAGE_THREAD は Linux 固有である。
注意
execve(2) の前後でリソース使用量の指標は保持される。
今 日では をインクルードする必要はないが、インクルードして
おけば移植性が増す。 (実際 struct timeval は で定義され て
いる。)
2.6.9 よ り 前 の バ ージョンの Linux カーネルでは、 SIGCHLD の処理が
SIG_IGN に設定されていると、子プロセスのリソース使用量 が RUSAGE_CHIL-
DREN で返される値に自動的に含められる。しかし POSIX.1-2001 では、これを
明確に禁止している。この準拠していなかった点は、Linux 2.6.9 以降で改 正
された。
こ の ページの最初で示した構造体の定義は 4.3BSD Reno のものを採用した。
Linux では全てのフィールドが意味を持つというわけではない。 Linux 2.4 で
は 、フィールド ru_utime, ru_stime, ru_minflt, ru_majflt のみがメンテナ
ンスされている。 Linux 2.6 以降では ru_nvcsw, ru_nivcsw もメンテナン ス
されている。
proc(5) にある /proc/PID/stat の説明も参照のこと。
関連項目
clock_gettime(2), getrlimit(2), times(2), wait(2), wait4(2), clock(3)
Linux 2008-10-06 GETRUSAGE(2)
GETRUSAGE(2) Linux Programmer’s Manual GETRUSAGE(2)
NAME
getrusage - get resource usage
SYNOPSIS
#include
#include
int getrusage(int who, struct rusage *usage);
DESCRIPTION
getrusage() returns resource usage measures for who, which can be one
of the following:
RUSAGE_SELF
Return resource usage statistics for the calling process, which
is the sum of resources used by all threads in the process.
RUSAGE_CHILDREN
Return resource usage statistics for all children of the calling
process that have terminated and been waited for. These statis-
tics will include the resources used by grandchildren, and fur-
ther removed descendants, if all of the intervening descendants
waited on their terminated children.
RUSAGE_THREAD (since Linux 2.6.26)
Return resource usage statistics for the calling thread.
The resource usages are returned in the structure pointed to by usage,
which has the following form:
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is
set appropriately.
ERRORS
EFAULT usage points outside the accessible address space.
EINVAL who is invalid.
CONFORMING TO
SVr4, 4.3BSD. POSIX.1-2001 specifies getrusage(), but only specifies
the fields ru_utime and ru_stime.
RUSAGE_THREAD is Linux-specific.
NOTES
Resource usage metrics are preserved across an execve(2).
Including is not required these days, but increases porta-
bility. (Indeed, struct timeval is defined in .)
In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
set to SIG_IGN then the resource usages of child processes are automat-
ically included in the value returned by RUSAGE_CHILDREN, although
POSIX.1-2001 explicitly prohibits this. This non-conformance is recti-
fied in Linux 2.6.9 and later.
The structure definition shown at the start of this page was taken from
4.3BSD Reno. Not all fields are meaningful under Linux. In Linux 2.4
only the fields ru_utime, ru_stime, ru_minflt, and ru_majflt are main-
tained. Since Linux 2.6, ru_nvcsw and ru_nivcsw are also maintained.
See also the description of /proc/PID/stat in proc(5).
SEE ALSO
clock_gettime(2), getrlimit(2), times(2), wait(2), wait4(2), clock(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-10-06 GETRUSAGE(2)