1acct(5)                       File Formats Manual                      acct(5)
2
3
4

NAME

6       acct - process accounting file
7

SYNOPSIS

9       #include <sys/acct.h>
10

DESCRIPTION

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 Linux 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

VERSIONS

101       Although it is present on most systems, it is not standardized, and the
102       details vary somewhat between systems.
103

STANDARDS

105       None.
106

HISTORY

108       glibc 2.6.
109
110       Process accounting originated on BSD.
111

NOTES

113       Records  in  the accounting file are ordered by termination time of the
114       process.
115
116       Up to and including Linux 2.6.9, a separate accounting record is  writ‐
117       ten  for  each  thread  created using the NPTL threading library; since
118       Linux 2.6.10, a single accounting record  is  written  for  the  entire
119       process on termination of the last thread in the process.
120
121       The  /proc/sys/kernel/acct file, described in proc(5), defines settings
122       that control the behavior of process accounting when  disk  space  runs
123       low.
124

SEE ALSO

126       lastcomm(1), acct(2), accton(8), sa(8)
127
128
129
130Linux man-pages 6.04              2023-03-30                           acct(5)
Impressum