OSDN Git Service

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