Changes: Ready for 5.13
[man-pages.git] / man5 / acct.5
blobe02cc6ef35cf4c2bcfd42d93b30b9555c9824a6a
1 .\" Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH ACCT 5 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 acct \- process accounting file
28 .SH SYNOPSIS
29 .nf
30 .B #include <sys/acct.h>
31 .fi
32 .SH DESCRIPTION
33 If the kernel is built with the process accounting option enabled
34 .RB ( CONFIG_BSD_PROCESS_ACCT ),
35 then calling
36 .BR acct (2)
37 starts process accounting, for example:
38 .PP
39 .in +4n
40 acct("/var/log/pacct");
41 .in
42 .PP
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,
46 and is defined in
47 .I <sys/acct.h>
48 as follows:
49 .PP
50 .in +4n
51 .EX
52 #define ACCT_COMM 16
54 typedef u_int16_t comp_t;
56 struct acct {
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
73                                (see wait(2)) */
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 */
86 .EE
87 .in
88 .PP
89 The
90 .I comp_t
91 data type is a floating-point value consisting of a 3-bit, base-8 exponent,
92 and a 13-bit mantissa.
93 A value,
94 .IR c ,
95 of this type can be converted to a (long) integer as follows:
96 .PP
97 .nf
98     v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
99 .fi
102 .IR ac_utime ,
103 .IR ac_stime ,
105 .I ac_etime
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
110 Since kernel 2.6.8,
111 an optional alternative version of the accounting file can be produced
112 if the
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,
117 and the width of
118 .I c_uid
120 .I ac_gid
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:
125 .in +4n
127 struct acct_v3 {
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
143                                (unused) */
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 */
151 .SH VERSIONS
153 .I acct_v3
154 structure is defined in glibc since version 2.6.
155 .SH CONFORMING TO
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.
159 .SH NOTES
160 Records in the accounting file are ordered by termination time of
161 the process.
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;
166 since Linux 2.6.10,
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
172 file, described in
173 .BR proc (5),
174 defines settings that control the behavior of process accounting
175 when disk space runs low.
176 .SH SEE ALSO
177 .BR lastcomm (1),
178 .BR acct (2),
179 .BR accton (8),
180 .BR sa (8)