1 .\" Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH ACCT 5 2021-03-22 "Linux" "Linux Programmer's Manual"
27 acct \- process accounting file
30 .B #include <sys/acct.h>
33 If the kernel is built with the process accounting option enabled
34 .RB ( CONFIG_BSD_PROCESS_ACCT ),
37 starts process accounting, for example:
40 acct("/var/log/pacct");
43 When process accounting is enabled, the kernel writes a record
44 to the accounting file as each process on the system terminates.
45 This record contains information about the terminated process,
54 typedef u_int16_t comp_t;
57 char ac_flag; /* Accounting flags */
58 u_int16_t ac_uid; /* Accounting user ID */
59 u_int16_t ac_gid; /* Accounting group ID */
60 u_int16_t ac_tty; /* Controlling terminal */
61 u_int32_t ac_btime; /* Process creation time
62 (seconds since the Epoch) */
63 comp_t ac_utime; /* User CPU time */
64 comp_t ac_stime; /* System CPU time */
65 comp_t ac_etime; /* Elapsed time */
66 comp_t ac_mem; /* Average memory usage (kB) */
67 comp_t ac_io; /* Characters transferred (unused) */
68 comp_t ac_rw; /* Blocks read or written (unused) */
69 comp_t ac_minflt; /* Minor page faults */
70 comp_t ac_majflt; /* Major page faults */
71 comp_t ac_swaps; /* Number of swaps (unused) */
72 u_int32_t ac_exitcode; /* Process termination status
74 char ac_comm[ACCT_COMM+1];
75 /* Command name (basename of last
76 executed command; null\-terminated) */
77 char ac_pad[\fIX\fP]; /* padding bytes */
80 enum { /* Bits that may be set in ac_flag field */
81 AFORK = 0x01, /* Has executed fork, but no exec */
82 ASU = 0x02, /* Used superuser privileges */
83 ACORE = 0x08, /* Dumped core */
84 AXSIG = 0x10 /* Killed by a signal */
91 data type is a floating-point value consisting of a 3-bit, base-8 exponent,
92 and a 13-bit mantissa.
95 of this type can be converted to a (long) integer as follows:
98 v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
106 fields measure time in "clock ticks"; divide these values by
107 .I sysconf(_SC_CLK_TCK)
108 to convert them to seconds.
109 .SS Version 3 accounting file format
111 an optional alternative version of the accounting file can be produced
113 .B CONFIG_BSD_PROCESS_ACCT_V3
114 option is set when building the kernel.
115 With this option is set,
116 the records written to the accounting file contain additional fields,
121 fields is widened from 16 to 32 bits
122 (in line with the increased size of UID and GIDs in Linux 2.4 and later).
123 The records are defined as follows:
128 char ac_flag; /* Flags */
129 char ac_version; /* Always set to ACCT_VERSION (3) */
130 u_int16_t ac_tty; /* Controlling terminal */
131 u_int32_t ac_exitcode; /* Process termination status */
132 u_int32_t ac_uid; /* Real user ID */
133 u_int32_t ac_gid; /* Real group ID */
134 u_int32_t ac_pid; /* Process ID */
135 u_int32_t ac_ppid; /* Parent process ID */
136 u_int32_t ac_btime; /* Process creation time */
137 float ac_etime; /* Elapsed time */
138 comp_t ac_utime; /* User CPU time */
139 comp_t ac_stime; /* System time */
140 comp_t ac_mem; /* Average memory usage (kB) */
141 comp_t ac_io; /* Characters transferred (unused) */
142 comp_t ac_rw; /* Blocks read or written
144 comp_t ac_minflt; /* Minor page faults */
145 comp_t ac_majflt; /* Major page faults */
146 comp_t ac_swaps; /* Number of swaps (unused) */
147 char ac_comm[ACCT_COMM]; /* Command name */
154 structure is defined in glibc since version 2.6.
156 Process accounting originated on BSD.
157 Although it is present on most systems, it is not standardized,
158 and the details vary somewhat between systems.
160 Records in the accounting file are ordered by termination time of
163 In kernels up to and including 2.6.9,
164 a separate accounting record is written for each thread created using
165 the NPTL threading library;
167 a single accounting record is written for the entire process
168 on termination of the last thread in the process.
171 .I /proc/sys/kernel/acct
174 defines settings that control the behavior of process accounting
175 when disk space runs low.