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 .TH ACCT 5 2008-06-15 "Linux" "Linux Programmer's Manual"
25 acct \- process accounting file
27 .B #include <sys/acct.h>
29 If the kernel is built with the process accounting option enabled
30 .RB ( CONFIG_BSD_PROCESS_ACCT ),
33 starts process accounting, for example:
36 acct("/var/log/pacct");
39 When process accounting is enabled, the kernel writes a record
40 to the accounting file as each process on the system terminates.
41 This record contains information about the terminated process,
50 typedef u_int16_t comp_t;
53 char ac_flag; /* Accounting flags */
54 u_int16_t ac_uid; /* Accounting user ID */
55 u_int16_t ac_gid; /* Accounting group ID */
56 u_int16_t ac_tty; /* Controlling terminal */
57 u_int32_t ac_btime; /* Process creation time
58 (seconds since the Epoch) */
59 comp_t ac_utime; /* User CPU time */
60 comp_t ac_stime; /* System CPU time */
61 comp_t ac_etime; /* Elapsed time */
62 comp_t ac_mem; /* Average memory usage (kB) */
63 comp_t ac_io; /* Characters transferred (unused) */
64 comp_t ac_rw; /* Blocks read or written (unused) */
65 comp_t ac_minflt; /* Minor page faults */
66 comp_t ac_majflt; /* Major page faults */
67 comp_t ac_swaps; /* Number of swaps (unused) */
68 u_int32_t ac_exitcode; /* Process termination status
70 char ac_comm[ACCT_COMM+1];
71 /* Command name (basename of last
72 executed command; null-terminated) */
73 char ac_pad[\fIX\fP]; /* padding bytes */
76 enum { /* Bits that may be set in ac_flag field */
77 AFORK = 0x01, /* Has executed fork, but no exec */
78 ASU = 0x02, /* Used superuser privileges */
79 ACORE = 0x08, /* Dumped core */
80 AXSIG = 0x10 /* Killed by a signal */
87 data type is a floating-point value consisting of a 3-bit, base-8 exponent,
88 and a 13-bit mantissa.
91 of this type can be converted to a (long) integer as follows:
94 v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
102 fields measure time in "clock ticks"; divide these values by
103 .I sysconf(_SC_CLK_TCK)
104 to convert them to seconds.
105 .SS Version 3 Accounting File Format
107 an optional alternative version of the accounting file can be produced
109 .B CONFIG_BSD_PROCESS_ACCT_V3
110 option is set when building the kernel.
111 With this option is set,
112 the records written to the accounting file contain additional fields,
117 fields is widened from 16 to 32 bits
118 (in line with the increased size of UID and GIDs in Linux 2.4 and later).
119 The records are defined as follows:
124 char ac_flag; /* Flags */
125 char ac_version; /* Always set to ACCT_VERSION (3) */
126 u_int16_t ac_tty; /* Controlling terminal */
127 u_int32_t ac_exitcode; /* Process termination status */
128 u_int32_t ac_uid; /* Real user ID */
129 u_int32_t ac_gid; /* Real group ID */
130 u_int32_t ac_pid; /* Process ID */
131 u_int32_t ac_ppid; /* Parent process ID */
132 u_int32_t ac_btime; /* Process creation time */
133 float ac_etime; /* Elapsed time */
134 comp_t ac_utime; /* User CPU time */
135 comp_t ac_stime; /* System time */
136 comp_t ac_mem; /* Average memory usage (kB) */
137 comp_t ac_io; /* Characters transferred (unused) */
138 comp_t ac_rw; /* Blocks read or written
140 comp_t ac_minflt; /* Minor page faults */
141 comp_t ac_majflt; /* Major page faults */
142 comp_t ac_swaps; /* Number of swaps (unused) */
143 char ac_comm[ACCT_COMM]; /* Command name */
151 structure is defined in glibc since version 2.6.
153 Process accounting originated on BSD.
154 Although it is present on most systems, it is not standardized,
155 and the details vary somewhat between systems.
157 Records in the accounting file are ordered by termination time of
160 In kernels up to and including 2.6.9,
161 a separate accounting record is written for each thread created using
162 the NPTL threading library;
164 a single accounting record is written for the entire process
165 on termination of the last thread in the process.
168 .I proc/sys/kernel/acct
171 defines settings that control the behavior of process accounting
172 when disk space runs low.