Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Linux Process Accounting (psacct) work?

Tags:

linux

kernel

I find a lot documents about psacct, but they are addressing usage, not how it works.

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.

  1. The service staring script actually (/etc/init.d/psacct) call this:

    /sbin/accton $ACCTFILE

  2. The /sbin/accton calls system call acct()

man acct

DESCRIPTION The acct() system call enables or disables process accounting. 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. An argument of NULL causes accounting to be turned off.

like image 743
feichashao Avatar asked Jan 02 '26 04:01

feichashao


1 Answers

The answer to your question is in the linux source file kernel/acct.c. Particularly in the 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)
like image 83
Ortomala Lokni Avatar answered Jan 06 '26 12:01

Ortomala Lokni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!