| 1 |
.\" Copyright 2008, Michael Kerrisk <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH acct 5 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
acct \- process accounting file |
| 9 |
.SH SYNOPSIS |
| 10 |
.nf |
| 11 |
.B #include <sys/acct.h> |
| 12 |
.fi |
| 13 |
.SH DESCRIPTION |
| 14 |
If the kernel is built with the process accounting option enabled |
| 15 |
.RB ( CONFIG_BSD_PROCESS_ACCT ), |
| 16 |
then calling |
| 17 |
.BR acct (2) |
| 18 |
starts process accounting, for example: |
| 19 |
.P |
| 20 |
.in +4n |
| 21 |
acct("/var/log/pacct"); |
| 22 |
.in |
| 23 |
.P |
| 24 |
When process accounting is enabled, the kernel writes a record |
| 25 |
to the accounting file as each process on the system terminates. |
| 26 |
This record contains information about the terminated process, |
| 27 |
and is defined in |
| 28 |
.I <sys/acct.h> |
| 29 |
as follows: |
| 30 |
.P |
| 31 |
.in +4n |
| 32 |
.EX |
| 33 |
#define ACCT_COMM 16 |
| 34 |
\& |
| 35 |
typedef u_int16_t comp_t; |
| 36 |
\& |
| 37 |
struct acct { |
| 38 |
char ac_flag; /* Accounting flags */ |
| 39 |
u_int16_t ac_uid; /* Accounting user ID */ |
| 40 |
u_int16_t ac_gid; /* Accounting group ID */ |
| 41 |
u_int16_t ac_tty; /* Controlling terminal */ |
| 42 |
u_int32_t ac_btime; /* Process creation time |
| 43 |
(seconds since the Epoch) */ |
| 44 |
comp_t ac_utime; /* User CPU time */ |
| 45 |
comp_t ac_stime; /* System CPU time */ |
| 46 |
comp_t ac_etime; /* Elapsed time */ |
| 47 |
comp_t ac_mem; /* Average memory usage (kB) */ |
| 48 |
comp_t ac_io; /* Characters transferred (unused) */ |
| 49 |
comp_t ac_rw; /* Blocks read or written (unused) */ |
| 50 |
comp_t ac_minflt; /* Minor page faults */ |
| 51 |
comp_t ac_majflt; /* Major page faults */ |
| 52 |
comp_t ac_swaps; /* Number of swaps (unused) */ |
| 53 |
u_int32_t ac_exitcode; /* Process termination status |
| 54 |
(see wait(2)) */ |
| 55 |
char ac_comm[ACCT_COMM+1]; |
| 56 |
/* Command name (basename of last |
| 57 |
executed command; null\-terminated) */ |
| 58 |
char ac_pad[\f[I]X\f[]]; /* padding bytes */ |
| 59 |
}; |
| 60 |
\& |
| 61 |
enum { /* Bits that may be set in ac_flag field */ |
| 62 |
AFORK = 0x01, /* Has executed fork, but no exec */ |
| 63 |
ASU = 0x02, /* Used superuser privileges */ |
| 64 |
ACORE = 0x08, /* Dumped core */ |
| 65 |
AXSIG = 0x10 /* Killed by a signal */ |
| 66 |
}; |
| 67 |
.EE |
| 68 |
.in |
| 69 |
.P |
| 70 |
The |
| 71 |
.I comp_t |
| 72 |
data type is a floating-point value consisting of a 3-bit, base-8 exponent, |
| 73 |
and a 13-bit mantissa. |
| 74 |
A value, |
| 75 |
.IR c , |
| 76 |
of this type can be converted to a (long) integer as follows: |
| 77 |
.P |
| 78 |
.nf |
| 79 |
v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3); |
| 80 |
.fi |
| 81 |
.P |
| 82 |
The |
| 83 |
.IR ac_utime , |
| 84 |
.IR ac_stime , |
| 85 |
and |
| 86 |
.I ac_etime |
| 87 |
fields measure time in "clock ticks"; |
| 88 |
divide these values by |
| 89 |
.I sysconf(_SC_CLK_TCK) |
| 90 |
to convert them to seconds. |
| 91 |
.SS Version 3 accounting file format |
| 92 |
Since Linux 2.6.8, |
| 93 |
an optional alternative version of the accounting file can be produced |
| 94 |
if the |
| 95 |
.B CONFIG_BSD_PROCESS_ACCT_V3 |
| 96 |
option is set when building the kernel. |
| 97 |
With this option is set, |
| 98 |
the records written to the accounting file contain additional fields, |
| 99 |
and the width of |
| 100 |
.I c_uid |
| 101 |
and |
| 102 |
.I ac_gid |
| 103 |
fields is widened from 16 to 32 bits |
| 104 |
(in line with the increased size of UID and GIDs in Linux 2.4 and later). |
| 105 |
The records are defined as follows: |
| 106 |
.P |
| 107 |
.in +4n |
| 108 |
.EX |
| 109 |
struct acct_v3 { |
| 110 |
char ac_flag; /* Flags */ |
| 111 |
char ac_version; /* Always set to ACCT_VERSION (3) */ |
| 112 |
u_int16_t ac_tty; /* Controlling terminal */ |
| 113 |
u_int32_t ac_exitcode; /* Process termination status */ |
| 114 |
u_int32_t ac_uid; /* Real user ID */ |
| 115 |
u_int32_t ac_gid; /* Real group ID */ |
| 116 |
u_int32_t ac_pid; /* Process ID */ |
| 117 |
u_int32_t ac_ppid; /* Parent process ID */ |
| 118 |
u_int32_t ac_btime; /* Process creation time */ |
| 119 |
float ac_etime; /* Elapsed time */ |
| 120 |
comp_t ac_utime; /* User CPU time */ |
| 121 |
comp_t ac_stime; /* System time */ |
| 122 |
comp_t ac_mem; /* Average memory usage (kB) */ |
| 123 |
comp_t ac_io; /* Characters transferred (unused) */ |
| 124 |
comp_t ac_rw; /* Blocks read or written |
| 125 |
(unused) */ |
| 126 |
comp_t ac_minflt; /* Minor page faults */ |
| 127 |
comp_t ac_majflt; /* Major page faults */ |
| 128 |
comp_t ac_swaps; /* Number of swaps (unused) */ |
| 129 |
char ac_comm[ACCT_COMM]; /* Command name */ |
| 130 |
}; |
| 131 |
.EE |
| 132 |
.in |
| 133 |
.SH VERSIONS |
| 134 |
Although it is present on most systems, it is not standardized, |
| 135 |
and the details vary somewhat between systems. |
| 136 |
.SH STANDARDS |
| 137 |
None. |
| 138 |
.SH HISTORY |
| 139 |
glibc 2.6. |
| 140 |
.P |
| 141 |
Process accounting originated on BSD. |
| 142 |
.SH NOTES |
| 143 |
Records in the accounting file are ordered by termination time of |
| 144 |
the process. |
| 145 |
.P |
| 146 |
Up to and including Linux 2.6.9, |
| 147 |
a separate accounting record is written for each thread created using |
| 148 |
the NPTL threading library; |
| 149 |
since Linux 2.6.10, |
| 150 |
a single accounting record is written for the entire process |
| 151 |
on termination of the last thread in the process. |
| 152 |
.P |
| 153 |
The |
| 154 |
.I /proc/sys/kernel/acct |
| 155 |
file, described in |
| 156 |
.BR proc (5), |
| 157 |
defines settings that control the behavior of process accounting |
| 158 |
when disk space runs low. |
| 159 |
.SH SEE ALSO |
| 160 |
.BR lastcomm (1), |
| 161 |
.BR acct (2), |
| 162 |
.BR accton (8), |
| 163 |
.BR sa (8) |