1 .\" Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
24 .\" all rights reserved.
25 .\" Translated 2008-08-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
27 .\"WORD: accounting アカウンティング
29 .TH ACCT 5 2008-06-15 "Linux" "Linux Programmer's Manual"
31 acct \- プロセス・アカウンティング・ファイル
33 .B #include <sys/acct.h>
35 カーネルがプロセス・アカウンティングのオプション
36 .RB ( CONFIG_BSD_PROCESS_ACCT )
39 を呼び出すとプロセス・アカウンティングが開始される。
42 acct("/var/log/pacct");
45 プロセス・アカウンティングが有効になっていると、カーネルは
46 システム上の各プロセスが終了するたびにアカウンティングファイルに
48 このレコードは、終了したプロセスに関する情報を保持するもので、
56 typedef u_int16_t comp_t;
59 char ac_flag; /* Accounting flags */
60 u_int16_t ac_uid; /* Accounting user ID */
61 u_int16_t ac_gid; /* Accounting group ID */
62 u_int16_t ac_tty; /* Controlling terminal */
63 u_int32_t ac_btime; /* Process creation time
64 (seconds since the Epoch) */
65 comp_t ac_utime; /* User CPU time */
66 comp_t ac_stime; /* System CPU time */
67 comp_t ac_etime; /* Elapsed time */
68 comp_t ac_mem; /* Average memory usage (kB) */
69 comp_t ac_io; /* Characters transferred (unused) */
70 comp_t ac_rw; /* Blocks read or written (unused) */
71 comp_t ac_minflt; /* Minor page faults */
72 comp_t ac_majflt; /* Major page faults */
73 comp_t ac_swaps; /* Number of swaps (unused) */
74 u_int32_t ac_exitcode; /* Process termination status
76 char ac_comm[ACCT_COMM+1];
77 /* Command name (basename of last
78 executed command; null-terminated) */
79 char ac_pad[\fIX\fP]; /* padding bytes */
82 enum { /* Bits that may be set in ac_flag field */
83 AFORK = 0x01, /* Has executed fork, but no exec */
84 ASU = 0x02, /* Used superuser privileges */
85 ACORE = 0x08, /* Dumped core */
86 AXSIG = 0x10 /* Killed by a signal */
93 は浮動小数点値で、3 ビット幅の基数が 8 の指数部と 13 ビット幅の仮数部から
98 は以下のようにして (long 型の) 整数に変換できる。
101 v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
108 は "clock ticks" 単位で計測した時間である。
110 .I sysconf(_SC_CLK_TCK)
112 .SS バージョン 3 のアカウンティングファイルのフォーマット
114 別のバージョンのアカウンティングファイルを生成することができ、
116 .B CONFIG_BSD_PROCESS_ACCT_V3
118 このオプションが設定されると、アカウンティングファイルに書き込まれる
124 の幅が 16 ビットから 32 ビットに拡張される
125 (これは Linux 2.4 以降で UID と GID のサイズが増えているのに
127 このレコードは以下のように定義されている。
132 char ac_flag; /* Flags */
133 char ac_version; /* Always set to ACCT_VERSION (3) */
134 u_int16_t ac_tty; /* Controlling terminal */
135 u_int32_t ac_exitcode; /* Process termination status */
136 u_int32_t ac_uid; /* Real user ID */
137 u_int32_t ac_gid; /* Real group ID */
138 u_int32_t ac_pid; /* Process ID */
139 u_int32_t ac_ppid; /* Parent process ID */
140 u_int32_t ac_btime; /* Process creation time */
141 float ac_etime; /* Elapsed time */
142 comp_t ac_utime; /* User CPU time */
143 comp_t ac_stime; /* System time */
144 comp_t ac_mem; /* Average memory usage (kB) */
145 comp_t ac_io; /* Characters transferred (unused) */
146 comp_t ac_rw; /* Blocks read or written
148 comp_t ac_minflt; /* Minor page faults */
149 comp_t ac_majflt; /* Major page faults */
150 comp_t ac_swaps; /* Number of swaps (unused) */
151 char ac_comm[ACCT_COMM]; /* Command name */
158 構造体はバージョン 2.6 以降の glibc で定義されている。
160 プロセスアカウンティングは BSD 由来である。
161 この機能はほとんどのシステムに存在するが、標準化されておらず、
164 アカウンティングファイルのレコードは、プロセスの終了時刻の順序となる。
166 バージョン 2.6.9 以前のカーネルでは、
167 NPTL スレッドライブラリを使って作成されたスレッドでは
168 スレッド毎に別々のアカウンティングレコードが書き込まれていた。
169 Linux 2.6.10 以降では、プロセス内の最後のスレッドが終了すると、
170 プロセス全体についてのアカウンティングレコードが一つだけ書き込まれる。
172 .I proc/sys/kernel/acct
175 で説明されている) は、ディスク容量の残りが少なくなった際の
176 プロセス・アカウンティングの動作を制御する設定を保持している。