遵循规范

流程记帐起源于BSD。尽管它存在于大多数系统中,但尚未标准化,并且各个系统之间的细节有所不同。

名称

acct-处理记帐文件

出版信息

这个页面是Linux手册页项目5.08版的一部分。有关项目的说明、有关报告错误的信息以及此页面的最新版本,请访问https://www.kernel.org/doc/man-pages/

ACCT - Linux手册页

Linux程序员手册 第5部分
更新日期: 2017-09-15

说明

如果构建内核时启用了进程记帐选项(CONFIG_BSD_PROCESS_ACCT),则调用acct(2)将启动进程记帐,例如:

acct(" / var / log / pacct");

启用进程记帐后,随着系统上的每个进程终止,内核将记录写入记帐文件。该记录包含有关终止的进程的信息,定义如下:

#define ACCT_COMM 16

typedef u_int16_t comp_t;

struct acct {
    char ac_flag;           /* Accounting flags */
    u_int16_t ac_uid;       /* Accounting user ID */
    u_int16_t ac_gid;       /* Accounting group ID */
    u_int16_t ac_tty;       /* Controlling terminal */
    u_int32_t ac_btime;     /* Process creation time
                               (seconds since the Epoch) */
    comp_t    ac_utime;     /* User CPU time */
    comp_t    ac_stime;     /* System CPU time */
    comp_t    ac_etime;     /* Elapsed time */
    comp_t    ac_mem;       /* Average memory usage (kB) */
    comp_t    ac_io;        /* Characters transferred (unused) */
    comp_t    ac_rw;        /* Blocks read or written (unused) */
    comp_t    ac_minflt;    /* Minor page faults */
    comp_t    ac_majflt;    /* Major page faults */
    comp_t    ac_swaps;     /* Number of swaps (unused) */
    u_int32_t ac_exitcode;  /* Process termination status
                               (see wait(2)) */
    char      ac_comm[ACCT_COMM+1];
                            /* Command name (basename of last
                               executed command; null-terminated) */
    char      ac_pad[X];    /* padding bytes */
};

enum {          /* Bits that may be set in ac_flag field */
    AFORK = 0x01,           /* Has executed fork, but no exec */
    ASU   = 0x02,           /* Used superuser privileges */
    ACORE = 0x08,           /* Dumped core */
    AXSIG = 0x10            /* Killed by a signal */
};

comp_t数据类型是一个浮点值,由3位,以8为底的指数和13位尾数组成。可以将这种类型的值c转换为(长)整数,如下所示:

v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);

ac_utime,ac_stime和ac_etime字段以"时钟滴答"为单位测量时间。将这些值除以sysconf(_SC_CLK_TCK)即可将其转换为秒。

Version 3 accounting file format

从内核2.6.8开始,如果在构建内核时设置了CONFIG_BSD_PROCESS_ACCT_V3选项,则可以生成计费文件的可选替代版本。设置此选项后,写入计费文件的记录将包含其他字段,并且c_uid和ac_gid字段的宽度从16位扩展到32位(与Linux 2.4及更高版本中UID和GID的增加大小一致)。记录定义如下:

struct acct_v3 {
    char      ac_flag;      /* Flags */
    char      ac_version;   /* Always set to ACCT_VERSION (3) */
    u_int16_t ac_tty;       /* Controlling terminal */
    u_int32_t ac_exitcode;  /* Process termination status */
    u_int32_t ac_uid;       /* Real user ID */
    u_int32_t ac_gid;       /* Real group ID */
    u_int32_t ac_pid;       /* Process ID */
    u_int32_t ac_ppid;      /* Parent process ID */
    u_int32_t ac_btime;     /* Process creation time */
    float     ac_etime;     /* Elapsed time */
    comp_t    ac_utime;     /* User CPU time */
    comp_t    ac_stime;     /* System time */
    comp_t    ac_mem;       /* Average memory usage (kB) */
    comp_t    ac_io;        /* Characters transferred (unused) */
    comp_t    ac_rw;        /* Blocks read or written
                               (unused) */
    comp_t    ac_minflt;    /* Minor page faults */
    comp_t    ac_majflt;    /* Major page faults */
    comp_t    ac_swaps;     /* Number of swaps (unused) */
    char      ac_comm[ACCT_COMM]; /* Command name */
};

备注

记帐文件中的记录按流程的终止时间排序。

在2.6.9(含)以下的内核中,将为使用NPTL线程库创建的每个线程编写单独的记帐记录。从Linux 2.6.10开始,在进程中的最后一个线程终止时,将为整个进程写入一条记帐记录。

proc(5)中描述的/ proc / sys / kernel / acct文件定义了一些设置,这些设置可在磁盘空间不足时控制进程记帐的行为。

语法

#包括

另外参见

lastcomm(1),acct(2),accton(8),sa(8)

版本

从2.6版开始,在glibc中定义了acct_v3结构。

日期:2019-08-20 18:01:48 来源:oir作者:oir