1ACCT(5) Linux Programmer's Manual ACCT(5)
2
3
4
6 acct - process accounting file
7
9 #include <sys/acct.h>
10
12 If the kernel is built with the process accounting option enabled (CON‐
13 FIG_BSD_PROCESS_ACCT), then calling acct(2) starts process accounting,
14 for example:
15
16 acct("/var/log/pacct");
17
18 When process accounting is enabled, the kernel writes a record to the
19 accounting file as each process on the system terminates. This record
20 contains information about the terminated process, and is defined in
21 <sys/acct.h> as follows:
22
23 #define ACCT_COMM 16
24
25 typedef u_int16_t comp_t;
26
27 struct acct {
28 char ac_flag; /* Accounting flags */
29 u_int16_t ac_uid; /* Accounting user ID */
30 u_int16_t ac_gid; /* Accounting group ID */
31 u_int16_t ac_tty; /* Controlling terminal */
32 u_int32_t ac_btime; /* Process creation time
33 (seconds since the Epoch) */
34 comp_t ac_utime; /* User CPU time */
35 comp_t ac_stime; /* System CPU time */
36 comp_t ac_etime; /* Elapsed time */
37 comp_t ac_mem; /* Average memory usage (kB) */
38 comp_t ac_io; /* Characters transferred (unused) */
39 comp_t ac_rw; /* Blocks read or written (unused) */
40 comp_t ac_minflt; /* Minor page faults */
41 comp_t ac_majflt; /* Major page faults */
42 comp_t ac_swaps; /* Number of swaps (unused) */
43 u_int32_t ac_exitcode; /* Process termination status
44 (see wait(2)) */
45 char ac_comm[ACCT_COMM+1];
46 /* Command name (basename of last
47 executed command; null-terminated) */
48 char ac_pad[X]; /* padding bytes */
49 };
50
51 enum { /* Bits that may be set in ac_flag field */
52 AFORK = 0x01, /* Has executed fork, but no exec */
53 ASU = 0x02, /* Used superuser privileges */
54 ACORE = 0x08, /* Dumped core */
55 AXSIG = 0x10 /* Killed by a signal */
56 };
57
58 The comp_t data type is a floating-point value consisting of a 3-bit,
59 base-8 exponent, and a 13-bit mantissa. A value, c, of this type can
60 be converted to a (long) integer as follows:
61
62 v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
63
64 The ac_utime, ac_stime, and ac_etime fields measure time in "clock
65 ticks"; divide these values by sysconf(_SC_CLK_TCK) to convert them to
66 seconds.
67
68 Version 3 Accounting File Format
69 Since kernel 2.6.8, an optional alternative version of the accounting
70 file can be produced if the CONFIG_BSD_PROCESS_ACCT_V3 option is set
71 when building the kernel. With this option is set, the records written
72 to the accounting file contain additional fields, and the width of
73 c_uid and ac_gid fields is widened from 16 to 32 bits (in line with the
74 increased size of UID and GIDs in Linux 2.4 and later). The records
75 are defined as follows:
76
77 struct acct_v3 {
78 char ac_flag; /* Flags */
79 char ac_version; /* Always set to ACCT_VERSION (3) */
80 u_int16_t ac_tty; /* Controlling terminal */
81 u_int32_t ac_exitcode; /* Process termination status */
82 u_int32_t ac_uid; /* Real user ID */
83 u_int32_t ac_gid; /* Real group ID */
84 u_int32_t ac_pid; /* Process ID */
85 u_int32_t ac_ppid; /* Parent process ID */
86 u_int32_t ac_btime; /* Process creation time */
87 float ac_etime; /* Elapsed time */
88 comp_t ac_utime; /* User CPU time */
89 comp_t ac_stime; /* System time */
90 comp_t ac_mem; /* Average memory usage (kB) */
91 comp_t ac_io; /* Characters transferred (unused) */
92 comp_t ac_rw; /* Blocks read or written
93 (unused) */
94 comp_t ac_minflt; /* Minor page faults */
95 comp_t ac_majflt; /* Major page faults */
96 comp_t ac_swaps; /* Number of swaps (unused) */
97 char ac_comm[ACCT_COMM]; /* Command name */
98 };
99
100
102 The acct_v3 structure is defined in glibc since version 2.6.
103
105 Process accounting originated on BSD. Although it is present on most
106 systems, it is not standardized, and the details vary somewhat between
107 systems.
108
110 Records in the accounting file are ordered by termination time of the
111 process.
112
113 In kernels up to and including 2.6.9, a separate accounting record is
114 written for each thread created using the NPTL threading library; since
115 Linux 2.6.10, a single accounting record is written for the entire
116 process on termination of the last thread in the process.
117
118 The proc/sys/kernel/acct file, described in proc(5), defines settings
119 that control the behavior of process accounting when disk space runs
120 low.
121
123 lastcomm(1), acct(2), accton(8), sa(8)
124
126 This page is part of release 3.25 of the Linux man-pages project. A
127 description of the project, and information about reporting bugs, can
128 be found at http://www.kernel.org/doc/man-pages/.
129
130
131
132Linux 2008-06-15 ACCT(5)