OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / man5 / acct.5
1 .\" Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH ACCT 5 2008-06-15 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 acct \- process accounting file
26 .SH SYNOPSIS
27 .B #include <sys/acct.h>
28 .SH DESCRIPTION
29 If the kernel is built with the process accounting option enabled
30 .RB ( CONFIG_BSD_PROCESS_ACCT ),
31 then calling
32 .BR acct (2)
33 starts process accounting, for example:
34
35 .in +4n
36 acct("/var/log/pacct");
37 .in
38
39 When process accounting is enabled, the kernel writes a record
40 to the accounting file as each process on the system terminates.
41 This record contains information about the terminated process,
42 and is defined in
43 .I <sys/acct.h>
44 as follows:
45
46 .in +4n
47 .nf
48 #define ACCT_COMM 16
49
50 typedef u_int16_t comp_t;
51
52 struct acct {
53     char ac_flag;           /* Accounting flags */
54     u_int16_t ac_uid;       /* Accounting user ID */
55     u_int16_t ac_gid;       /* Accounting group ID */
56     u_int16_t ac_tty;       /* Controlling terminal */
57     u_int32_t ac_btime;     /* Process creation time
58                                (seconds since the Epoch) */
59     comp_t    ac_utime;     /* User CPU time */
60     comp_t    ac_stime;     /* System CPU time */
61     comp_t    ac_etime;     /* Elapsed time */
62     comp_t    ac_mem;       /* Average memory usage (kB) */
63     comp_t    ac_io;        /* Characters transferred (unused) */
64     comp_t    ac_rw;        /* Blocks read or written (unused) */
65     comp_t    ac_minflt;    /* Minor page faults */
66     comp_t    ac_majflt;    /* Major page faults */
67     comp_t    ac_swaps;     /* Number of swaps (unused) */
68     u_int32_t ac_exitcode;  /* Process termination status
69                                (see wait(2)) */
70     char      ac_comm[ACCT_COMM+1];
71                             /* Command name (basename of last
72                                executed command; null-terminated) */
73     char      ac_pad[\fIX\fP];    /* padding bytes */
74 };
75
76 enum {          /* Bits that may be set in ac_flag field */
77     AFORK = 0x01,           /* Has executed fork, but no exec */
78     ASU   = 0x02,           /* Used superuser privileges */
79     ACORE = 0x08,           /* Dumped core */
80     AXSIG = 0x10            /* Killed by a signal */
81 };
82 .fi
83 .in
84 .PP
85 The
86 .I comp_t
87 data type is a floating-point value consisting of a 3-bit, base-8 exponent,
88 and a 13-bit mantissa.
89 A value,
90 .IR c ,
91 of this type can be converted to a (long) integer as follows:
92 .nf
93
94     v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
95 .fi
96 .PP
97 The
98 .IR ac_utime ,
99 .IR ac_stime ,
100 and
101 .I ac_etime
102 fields measure time in "clock ticks"; divide these values by
103 .I sysconf(_SC_CLK_TCK)
104 to convert them to seconds.
105 .SS Version 3 Accounting File Format
106 Since kernel 2.6.8,
107 an optional alternative version of the accounting file can be produced
108 if the
109 .B CONFIG_BSD_PROCESS_ACCT_V3
110 option is set when building the kernel.
111 With this option is set,
112 the records written to the accounting file contain additional fields,
113 and the width of
114 .I c_uid
115 and
116 .I ac_gid
117 fields is widened from 16 to 32 bits
118 (in line with the increased size of UID and GIDs in Linux 2.4 and later).
119 The records are defined as follows:
120
121 .in +4n
122 .nf
123 struct acct_v3 {
124     char      ac_flag;      /* Flags */
125     char      ac_version;   /* Always set to ACCT_VERSION (3) */
126     u_int16_t ac_tty;       /* Controlling terminal */
127     u_int32_t ac_exitcode;  /* Process termination status */
128     u_int32_t ac_uid;       /* Real user ID */
129     u_int32_t ac_gid;       /* Real group ID */
130     u_int32_t ac_pid;       /* Process ID */
131     u_int32_t ac_ppid;      /* Parent process ID */
132     u_int32_t ac_btime;     /* Process creation time */
133     float     ac_etime;     /* Elapsed time */
134     comp_t    ac_utime;     /* User CPU time */
135     comp_t    ac_stime;     /* System time */
136     comp_t    ac_mem;       /* Average memory usage (kB) */
137     comp_t    ac_io;        /* Characters transferred (unused) */
138     comp_t    ac_rw;        /* Blocks read or written
139                                (unused) */
140     comp_t    ac_minflt;    /* Minor page faults */
141     comp_t    ac_majflt;    /* Major page faults */
142     comp_t    ac_swaps;     /* Number of swaps (unused) */
143     char      ac_comm[ACCT_COMM]; /* Command name */
144 };
145
146 .fi
147 .in
148 .SH VERSIONS
149 The
150 .I acct_v3
151 structure is defined in glibc since version 2.6.
152 .SH CONFORMING TO
153 Process accounting originated on BSD.
154 Although it is present on most systems, it is not standardized,
155 and the details vary somewhat between systems.
156 .SH NOTES
157 Records in the accounting file are ordered by termination time of
158 the process.
159
160 In kernels up to and including 2.6.9,
161 a separate accounting record is written for each thread created using
162 the NPTL threading library;
163 since Linux 2.6.10,
164 a single accounting record is written for the entire process
165 on termination of the last thread in the process.
166
167 The
168 .I proc/sys/kernel/acct
169 file, described in
170 .BR proc (5),
171 defines settings that control the behavior of process accounting
172 when disk space runs low.
173 .SH "SEE ALSO"
174 .BR lastcomm (1),
175 .BR acct (2),
176 .BR accton (8),
177 .BR sa (8)