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