Chinaunix
标题:
Linux进程会计 struct acct中,ac_comm无法正常打印,为乱码?
[打印本页]
作者:
hohoss
时间:
2011-04-09 00:58
标题:
Linux进程会计 struct acct中,ac_comm无法正常打印,为乱码?
本帖最后由 hohoss 于 2011-04-09 01:01 编辑
APUE 8.14 进程会计程序
sudo accton on后,会计记录写入到/var/log/account/pacct
$程序名 /varlog/account/pacct
执行后,ac.comm段均为乱码。
但可用lastmm打印显示相关信息
#define FMT "%s e = %6ld, chars = %7ld, %c %c %c %c\n"
...............................................................
if ((fp = fopen(argv[1], "r")) == NULL) {
err_sys("CAn't open %s\n", argv[1]);
}
while ((fread(&acdata, sizeof(acdata), 1, fp)) == 1) {
printf(FMT, acdata.ac_comm,
compt2ulong(acdata.ac_etime), compt2ulong(acdata.ac_io),
acdata.ac_flag & ACORE ? 'D' : ' ', acdata.ac_flag & AXSIG ? 'X' : ' ',
acdata.ac_flag & AFORK ? 'F' : ' ', acdata.ac_flag & ASU ? 'S' : ' ');
}
........................................................
为什么呢
作者:
hohoss
时间:
2011-04-10 03:29
本帖最后由 hohoss 于 2011-04-10 03:46 编辑
找到原因了。。。
FUCK。。。
ubuntu下
accton on命令所创建的进程会计记录文件,采用的不是struct acct格式,而是struct acct_v3格式
虽然这两种格式都在sys/acct.h中有定义
改成acct_v3就可以正常使用了
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2