我目前在Centos上使用psacct软件包来执行用户运行的进程的记帐。
info文件1build议可以输出pid和ppid,这取决于你的操作系统在struct acct中提供的信息。
pid和ppid列在我系统上的/usr/include/linux/acct.h中:
struct acct_v3 { char ac_flag; /* Flags */ char ac_version; /* Always set to ACCT_VERSION */ __u16 ac_tty; /* Control Terminal */ __u32 ac_exitcode; /* Exitcode */ __u32 ac_uid; /* Real User ID */ __u32 ac_gid; /* Real Group ID */ __u32 ac_pid; /* Process ID */ __u32 ac_ppid; /* Parent Process ID */ ...
但是,当我运行dump-acct时,不会输出pid和ppid:
# dump-acct /var/account/pacct.1 | tail awk | 0.0| 0.0| 81.0| 0| 0|8792.0|Thu Nov 24 04:03:04 2011 tmpwatch | 0.0| 0.0| 1.0| 0| 0|3816.0|Thu Nov 24 04:03:04 2011 cups | 0.0| 0.0| 4.0| 0| 0|8728.0|Thu Nov 24 04:03:04 2011 awk | 0.0| 0.0| 4.0| 0| 0|8792.0|Thu Nov 24 04:03:04 2011 runlevel | 0.0| 0.0| 0.0| 0| 0|3804.0|Thu Nov 24 04:03:04 2011 chkconfig | 0.0| 0.0| 0.0| 0| 0|3840.0|Thu Nov 24 04:03:04 2011 inn-cron-expire | 0.0| 0.0| 0.0| 0| 0|8728.0|Thu Nov 24 04:03:04 2011 awk | 0.0| 0.0| 0.0| 0| 0|8792.0|Thu Nov 24 04:03:04 2011 gzip | 5.0| 0.0| 9.0| 0| 0|4044.0|Thu Nov 24 04:03:04 2011 accton | 0.0| 0.0| 1.0| 0| 0| 0.0|Thu Nov 24 04:03:04 2011
是否有可能在我的内核没有支持这个function,或者我的psacct版本不支持这个?
如何将pid和ppid添加到我的会计logging中?
CentOS版本5.6
内核2.6.18-238.19.1.el5
psacct 6.3.2
我刚刚在psacct RPM的更新日志中发现了这一点:
* Fri Nov 13 2009 Ivana Varekova <varekova(at)redhat.com> - 6.3.2-56 - fix the psacct to deal with all acct types and if it is possible and wanted then add the possibility to display the pid and ppid number
所以看起来好像取决于你正在使用的版本。
CentOS release 5.6 psacct 6.3.2
CentOS 5.6附带的psacct软件包的版本号为44:
Name : psacct Arch : x86_64 Version : 6.3.2 Release : 44.el5 Size : 107 k Repo : installed Summary : Utilities for monitoring process activities. License : GPL Description: The psacct package contains several utilities for monitoring process : activities, including ac, lastcomm, accton and sa. The ac command : displays statistics about how long users have been logged on. The : lastcomm command displays information about previous executed : commands. The accton command turns process accounting on or off. The : sa command summarizes information about previously executed : commands.
正如@Ladadadada提到的,根据更改日志,PID和PPID只能在6.3.2-56版本中使用。 在我的CentOS 6(psacct-6.3.2-63)上:
accton | 0.0| 0.0| 1.0| 0| 0|3832.0| 16114 16111|Thu Nov 24 13:37:50 2011 touch | 0.0| 0.0| 3.0| 0| 0|105088.0| 16115 16111|Thu Nov 24 13:37:50 2011 psacct | 0.0| 0.0| 9.0| 0| 0|106304.0| 16111 16059|Thu Nov 24 13:37:50 2011 w | 0.0| 0.0| 3.0| 0| 0|105280.0| 16116 16059|Thu Nov 24 13:37:52 2011