简体   繁体   English

Linux Process Accounting(psacct)如何工作?

[英]How does Linux Process Accounting (psacct) work?

I find a lot documents about psacct , but they are addressing usage, not how it works. 我找到了很多关于psacct文档,但它们正在解决使用问题,而不是它的工作方式。

Question

I really want to know how process accounting works: 我真的想知道流程会计的工作原理:

  1. Which part of the system records information about processes? 系统的哪个部分记录有关进程的信息?

  2. How does it work? 它是如何工作的?

Already done 已经完成了

I installed psacct on RHEL 6.5. 我在RHEL 6.5上安装了psacct。

  1. The service staring script actually (/etc/init.d/psacct) call this: 服务启动脚本实际上(/etc/init.d/psacct)调用这个:

    /sbin/accton $ACCTFILE / sbin / accton $ ACCTFILE

  2. The /sbin/accton calls system call acct() / sbin / accton调用系统调用acct()

man acct 男人的

DESCRIPTION The acct() system call enables or disables process accounting. 描述acct()系统调用启用或禁用进程记帐。 If called with the name of an existing file as its argument, accounting is turned on, and records for each terminating process are appended to filename as it terminates. 如果使用现有文件的名称作为其参数进行调用,则会启用记帐,并在终止时将每个终止进程的记录附加到filename。 An argument of NULL causes accounting to be turned off. NULL参数会导致会计被关闭。

The answer to your question is in the linux source file kernel/acct.c . 您的问题的答案在linux源文件kernel/acct.c Particularly in the fill_ac function 特别是在fill_ac function

/*
 *  Write an accounting entry for an exiting process
 *
 *  The acct_process() call is the workhorse of the process
 *  accounting system. The struct acct is built here and then written
 *  into the accounting file. This function should only be called from
 *  do_exit() or when switching to a different output file.
 */

static void fill_ac(acct_t *ac)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM