Blame man5/acct.5

Packit 7cfc04
.\" Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH ACCT 5 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
acct \- process accounting file
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <sys/acct.h>
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
If the kernel is built with the process accounting option enabled
Packit 7cfc04
.RB ( CONFIG_BSD_PROCESS_ACCT ),
Packit 7cfc04
then calling
Packit 7cfc04
.BR acct (2)
Packit 7cfc04
starts process accounting, for example:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
acct("/var/log/pacct");
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
When process accounting is enabled, the kernel writes a record
Packit 7cfc04
to the accounting file as each process on the system terminates.
Packit 7cfc04
This record contains information about the terminated process,
Packit 7cfc04
and is defined in
Packit 7cfc04
.I <sys/acct.h>
Packit 7cfc04
as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
#define ACCT_COMM 16
Packit 7cfc04
Packit 7cfc04
typedef u_int16_t comp_t;
Packit 7cfc04
Packit 7cfc04
struct acct {
Packit 7cfc04
    char ac_flag;           /* Accounting flags */
Packit 7cfc04
    u_int16_t ac_uid;       /* Accounting user ID */
Packit 7cfc04
    u_int16_t ac_gid;       /* Accounting group ID */
Packit 7cfc04
    u_int16_t ac_tty;       /* Controlling terminal */
Packit 7cfc04
    u_int32_t ac_btime;     /* Process creation time
Packit 7cfc04
                               (seconds since the Epoch) */
Packit 7cfc04
    comp_t    ac_utime;     /* User CPU time */
Packit 7cfc04
    comp_t    ac_stime;     /* System CPU time */
Packit 7cfc04
    comp_t    ac_etime;     /* Elapsed time */
Packit 7cfc04
    comp_t    ac_mem;       /* Average memory usage (kB) */
Packit 7cfc04
    comp_t    ac_io;        /* Characters transferred (unused) */
Packit 7cfc04
    comp_t    ac_rw;        /* Blocks read or written (unused) */
Packit 7cfc04
    comp_t    ac_minflt;    /* Minor page faults */
Packit 7cfc04
    comp_t    ac_majflt;    /* Major page faults */
Packit 7cfc04
    comp_t    ac_swaps;     /* Number of swaps (unused) */
Packit 7cfc04
    u_int32_t ac_exitcode;  /* Process termination status
Packit 7cfc04
                               (see wait(2)) */
Packit 7cfc04
    char      ac_comm[ACCT_COMM+1];
Packit 7cfc04
                            /* Command name (basename of last
Packit 7cfc04
                               executed command; null-terminated) */
Packit 7cfc04
    char      ac_pad[\fIX\fP];    /* padding bytes */
Packit 7cfc04
};
Packit 7cfc04
Packit 7cfc04
enum {          /* Bits that may be set in ac_flag field */
Packit 7cfc04
    AFORK = 0x01,           /* Has executed fork, but no exec */
Packit 7cfc04
    ASU   = 0x02,           /* Used superuser privileges */
Packit 7cfc04
    ACORE = 0x08,           /* Dumped core */
Packit 7cfc04
    AXSIG = 0x10            /* Killed by a signal */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I comp_t
Packit 7cfc04
data type is a floating-point value consisting of a 3-bit, base-8 exponent,
Packit 7cfc04
and a 13-bit mantissa.
Packit 7cfc04
A value,
Packit 7cfc04
.IR c ,
Packit 7cfc04
of this type can be converted to a (long) integer as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.nf
Packit 7cfc04
    v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.IR ac_utime ,
Packit 7cfc04
.IR ac_stime ,
Packit 7cfc04
and
Packit 7cfc04
.I ac_etime
Packit 7cfc04
fields measure time in "clock ticks"; divide these values by
Packit 7cfc04
.I sysconf(_SC_CLK_TCK)
Packit 7cfc04
to convert them to seconds.
Packit 7cfc04
.SS Version 3 accounting file format
Packit 7cfc04
Since kernel 2.6.8,
Packit 7cfc04
an optional alternative version of the accounting file can be produced
Packit 7cfc04
if the
Packit 7cfc04
.B CONFIG_BSD_PROCESS_ACCT_V3
Packit 7cfc04
option is set when building the kernel.
Packit 7cfc04
With this option is set,
Packit 7cfc04
the records written to the accounting file contain additional fields,
Packit 7cfc04
and the width of
Packit 7cfc04
.I c_uid
Packit 7cfc04
and
Packit 7cfc04
.I ac_gid
Packit 7cfc04
fields is widened from 16 to 32 bits
Packit 7cfc04
(in line with the increased size of UID and GIDs in Linux 2.4 and later).
Packit 7cfc04
The records are defined as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct acct_v3 {
Packit 7cfc04
    char      ac_flag;      /* Flags */
Packit 7cfc04
    char      ac_version;   /* Always set to ACCT_VERSION (3) */
Packit 7cfc04
    u_int16_t ac_tty;       /* Controlling terminal */
Packit 7cfc04
    u_int32_t ac_exitcode;  /* Process termination status */
Packit 7cfc04
    u_int32_t ac_uid;       /* Real user ID */
Packit 7cfc04
    u_int32_t ac_gid;       /* Real group ID */
Packit 7cfc04
    u_int32_t ac_pid;       /* Process ID */
Packit 7cfc04
    u_int32_t ac_ppid;      /* Parent process ID */
Packit 7cfc04
    u_int32_t ac_btime;     /* Process creation time */
Packit 7cfc04
    float     ac_etime;     /* Elapsed time */
Packit 7cfc04
    comp_t    ac_utime;     /* User CPU time */
Packit 7cfc04
    comp_t    ac_stime;     /* System time */
Packit 7cfc04
    comp_t    ac_mem;       /* Average memory usage (kB) */
Packit 7cfc04
    comp_t    ac_io;        /* Characters transferred (unused) */
Packit 7cfc04
    comp_t    ac_rw;        /* Blocks read or written
Packit 7cfc04
                               (unused) */
Packit 7cfc04
    comp_t    ac_minflt;    /* Minor page faults */
Packit 7cfc04
    comp_t    ac_majflt;    /* Major page faults */
Packit 7cfc04
    comp_t    ac_swaps;     /* Number of swaps (unused) */
Packit 7cfc04
    char      ac_comm[ACCT_COMM]; /* Command name */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
The
Packit 7cfc04
.I acct_v3
Packit 7cfc04
structure is defined in glibc since version 2.6.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
Process accounting originated on BSD.
Packit 7cfc04
Although it is present on most systems, it is not standardized,
Packit 7cfc04
and the details vary somewhat between systems.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Records in the accounting file are ordered by termination time of
Packit 7cfc04
the process.
Packit 7cfc04
.PP
Packit 7cfc04
In kernels up to and including 2.6.9,
Packit 7cfc04
a separate accounting record is written for each thread created using
Packit 7cfc04
the NPTL threading library;
Packit 7cfc04
since Linux 2.6.10,
Packit 7cfc04
a single accounting record is written for the entire process
Packit 7cfc04
on termination of the last thread in the process.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I /proc/sys/kernel/acct
Packit 7cfc04
file, described in
Packit 7cfc04
.BR proc (5),
Packit 7cfc04
defines settings that control the behavior of process accounting
Packit 7cfc04
when disk space runs low.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR lastcomm (1),
Packit 7cfc04
.BR acct (2),
Packit 7cfc04
.BR accton (8),
Packit 7cfc04
.BR sa (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.