了解/var/account/pacct或者/var/account/acct Acct文件格式
时间:2020-01-09 10:42:09 来源:igfitidea点击:
问题描述:您能在Linux/UNIX操作系统下解释/var/account/pacct或者/var/log/account/pacct文件吗?
解决方法:acct文件(/var/account/acct或者/var/account/pacct)格式在UNIX/Linux/BSD操作系统中很常见。
内核将启动进程记帐并存储在/var/account/pacct或者/var/log/account/pacct文件中,对于UNIX/Linux之类的操作系统,该文件在系统范围内是" unix进程记帐"或者" unix记帐文件"。
文件的位置和名称取决于UNIX/Linux变体:
- FreeBSD/OpenBSD的默认记帐文件:
/var/account/acct - 红帽/RHEL/CentOS/Fedora Linux:
/var/account/pacct - Debian/Ubuntu Linux:
/var/log/account/pacct - Sun Solaris UNIX缺省记帐文件:
/var/adm/pacct
accton命令
accton实用程序用于打开或者关闭系统记帐。
如果使用参数acctfile调用,则启用系统记帐。
指定的acctfile必须在启动系统记帐之前存在,否则accton将返回错误。
您可以按以下方式运行accton:
# accton /path/to/file # accton /var/account/acct
在Red Hat/CentOS Linux下,您可以输入以下命令来启动计费服务:
# chkconfig psacct on # /etc/init.d/psacct
在Ubuntu/Debian Linux下,您需要输入以下命令来启动计费服务:
# update-rc.d acct defaults /etc/init.d/acct start
acct文件格式
内核为所有进程维护以下acct信息结构。
如果进程终止并且启用了记帐,则内核会调用acct(2)函数调用来准备记录并将其追加到记帐文件中。
#define AC_COMM_LEN 16
/*
* Accounting structure version 2 (current).
* The first byte is always zero.
* Time units are microseconds.
*/
struct acctv2 {
uint8_t ac_zero; /* zero identifies new version */
uint8_t ac_version; /* record version number */
uint16_t ac_len; /* record length */
char ac_comm[AC_COMM_LEN]; /* command name */
float ac_utime; /* user time */
float ac_stime; /* system time */
float ac_etime; /* elapsed time */
time_t ac_btime; /* starting time */
uid_t ac_uid; /* user id */
gid_t ac_gid; /* group id */
float ac_mem; /* average memory usage */
float ac_io; /* count of IO blocks */
__dev_t ac_tty; /* controlling tty */
uint16_t ac_len2; /* record length */
union {
__dev_t ac_align; /* force v1 compatible alignment */
#define AFORK 0x01 /* forked but not exec'ed */
/* ASU is no longer supported */
#define ASU 0x02 /* used super-user permissions */
#define ACOMPAT 0x04 /* used compatibility mode */
#define ACORE 0x08 /* dumped core */
#define AXSIG 0x10 /* killed by a signal */
#define ANVER 0x20 /* new record version */
uint8_t ac_flag; /* accounting flags */
} ac_trailer;
#define ac_flagx ac_trailer.ac_flag
};
如果由execve(2)创建了终止的进程,则已执行文件的名称(最多10个字符)保存在ac_comm字段中,并且通过在ac_flag中设置以下多个标志之一来保存其状态: AFORK,ACOMPAT,ACORE和ASIG。
不再支持ASU。
总是在上述结构中设置ANVER。
如何使用acct文件?
您需要使用lastcomm或者sa命令使用acct文件。

