.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992 .\" and Copyright (c) 2002 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. .\" .\" 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. .\" .\" 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 .\" .TH GETRUSAGE 2 2009-08-25 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O getrusage \- get resource usage getrusage \- 資源の使用量を取得する .\"O .SH SYNOPSIS .SH 書式 .B #include .br .B #include .sp .BI "int getrusage(int " who ", struct rusage *" usage ); .\"O .SH DESCRIPTION .SH 説明 .PP .\"O .BR getrusage () .\"O returns resource usage measures for .\"O .IR who , .\"O which can be one of the following: .BR getrusage () は .I who の資源 (resource) の使用量を返す。 .I who には以下のいずれか一つを指定できる。 .TP .B RUSAGE_SELF .\"O Return resource usage statistics for the calling process, .\"O which is the sum of resources used by all threads in the process. 呼び出したプロセスの資源使用量、 そのプロセス内の全スレッドが使用している資源の合計を返す。 前者は呼び出したプロセスのリソース使用量を要求し、 後者は呼び出したプロセスの子供のうち 終了して待ち状態にあるプロセスの使用量を要求する。 .TP .B RUSAGE_CHILDREN .\"O Return resource usage statistics for all children of the .\"O calling process that have terminated and been waited for. .\"O These statistics will include the resources used by grandchildren, .\"O and further removed descendants, .\"O if all of the intervening descendants waited on their terminated children. .\"Omotoki: 訳に自信なし (特に if all of .... 以降が今いち理解できず) 呼び出したプロセスの子プロセスのうち、 終了して待ち状態にある全プロセスが使用している資源使用量の統計を返す。 これらの統計情報には、孫プロセスやその子孫のプロセスのうち、 削除待ちのものが使用している資源も含まれる。 .TP .\"O .BR RUSAGE_THREAD " (since Linux 2.6.26)" .BR RUSAGE_THREAD " (Linux 2.6.26 以降)" .\"O Return resource usage statistics for the calling thread. 呼び出したスレッドに関する資源使用量の統計を返す。 .PP .\"O The resource usages are returned in the structure pointed to by .\"O .IR usage , .\"O which has the following form: 資源使用量は .I usage が指す構造体に格納されて返される。 構造体は以下の形式である。 .PP .in +4n .nf struct rusage { .\"O struct timeval ru_utime; /* user time used */ .\"O struct timeval ru_stime; /* system time used */ .\"O long ru_maxrss; /* maximum resident set size */ .\"O long ru_ixrss; /* integral shared memory size */ .\"O long ru_idrss; /* integral unshared data size */ .\"O long ru_isrss; /* integral unshared stack size */ .\"O long ru_minflt; /* page reclaims */ .\"O long ru_majflt; /* page faults */ .\"O long ru_nswap; /* swaps */ .\"O long ru_inblock; /* block input operations */ .\"O long ru_oublock; /* block output operations */ .\"O long ru_msgsnd; /* messages sent */ .\"O long ru_msgrcv; /* messages received */ .\"O long ru_nsignals; /* signals received */ .\"O long ru_nvcsw; /* voluntary context switches */ .\"O long ru_nivcsw; /* involuntary context switches */ 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; /* 意図しないコンテキスト切り替え */ }; .fi .in .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, zero is returned. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 .I errno に適切な値が設定される。 .\"O .SH ERRORS .SH エラー .TP .B EFAULT .\"O .I usage .\"O points outside the accessible address space. .I usage がアクセス可能なアドレス空間の外を指している。 .TP .B EINVAL .\"O .I who .\"O is invalid. .I who が無効である。 .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, 4.3BSD. .\"O POSIX.1-2001 specifies .\"O .BR getrusage (), .\"O but only specifies the fields .\"O .I ru_utime .\"O and .\"O .IR ru_stime . POSIX.1-2001 は .BR getrusage () を規定しているが、規定しているフィールドは .I ru_utime と .I ru_stime だけである。 .\"O .B RUSAGE_THREAD .\"O is Linux-specific. .B RUSAGE_THREAD は Linux 固有である。 .\"O .SH NOTES .SH 注意 .\"O Resource usage metrics are preserved across an .\"O .BR execve (2). .BR execve (2) の前後でリソース使用量の指標は保持される。 .\"O Including .\"O .I .\"O is not required these days, but increases portability. .\"O (Indeed, .\"O .I struct timeval .\"O is defined in .\"O .IR .) 今日では .I をインクルードする必要はないが、 インクルードしておけば移植性が増す。 (実際 .I struct timeval は .I で定義されている。) .PP .\"O In Linux kernel versions before 2.6.9, if the disposition of .\"O .B SIGCHLD .\"O is set to .\"O .B SIG_IGN .\"O then the resource usages of child processes .\"O are automatically included in the value returned by .\"O .BR RUSAGE_CHILDREN , .\"O although POSIX.1-2001 explicitly prohibits this. 2.6.9 より前のバージョンの Linux カーネルでは、 .B SIGCHLD の処理が .B SIG_IGN に設定されていると、 子プロセスのリソース使用量が .B RUSAGE_CHILDREN で返される値に自動的に含められる。 しかし POSIX.1-2001 では、これを明確に禁止している。 .\"O This nonconformance is rectified in Linux 2.6.9 and later. .\"O .\" See the description of getrusage() in XSH. .\"O .\" A similar statement was also in SUSv2. この準拠していなかった点は、Linux 2.6.9 以降で改正された。 .\" XSH の getrusage() の説明を参照すること。 .\" 同様の記述は SUSv2 にもある。 .LP .\"O The structure definition shown at the start of this page .\"O was taken from 4.3BSD Reno. .\"O Not all fields are meaningful under Linux. .\"O In Linux 2.4 only the fields .\"O .IR ru_utime , .\"O .IR ru_stime , .\"O .IR ru_minflt , .\"O and .\"O .I ru_majflt .\"O are maintained. このページの最初で示した構造体の定義は 4.3BSD Reno のものを採用した。 Linux では全てのフィールドが意味を持つというわけではない。 Linux 2.4 では、フィールド .IR ru_utime , .IR ru_stime , .IR ru_minflt , .I ru_majflt のみがメンテナンスされている。 .\"O Since Linux 2.6, .\"O .I ru_nvcsw .\"O and .\"O .I ru_nivcsw .\"O are also maintained. Linux 2.6 以降では .IR ru_nvcsw , .I ru_nivcsw もメンテナンスされている。 .\"O Since Linux 2.6.22, .\"O .I ru_inblock .\"O and .\"O .I ru_oublock .\"O are also maintained. Linux 2.6.22 以降では .IR ru_inblock , .I ru_oublock もメンテナンスされている。 .\"O See also the description of .\"O .IR /proc/PID/stat .\"O in .\"O .BR proc (5). .BR proc (5) にある .I /proc/PID/stat の説明も参照のこと。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR clock_gettime (2), .BR getrlimit (2), .BR times (2), .BR wait (2), .BR wait4 (2), .BR clock (3)