如何在 psacct dump-acct 中啟用 pid 和 ppid 欄位?

如何在 psacct dump-acct 中啟用 pid 和 ppid 欄位?

我目前正在 Centos 上使用 psacct 套件對用戶運行的進程進行記帳。

資訊檔案1建議根據作業系統在 struct acct 中提供的資訊來輸出 pid 和 ppid。

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

我的核心是否可能不支援此功能,或者我的 psacct 版本不支援此功能?

如何將 pid 和 ppid 加入到我的記帳日誌中?

CentOS 5.6 版本

內核2.6.18-238.19.1.el5

psacct 6.3.2

答案1

我剛剛在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

所以看起來這完全取決於您正在使用的版本。

答案2

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

相關內容