I've been looking at using process accounting for keeping track of various users and sites running scripts that are problematic in our environment instead of trying to do something like scraping top at regular intervals.

The one that isn't particularly clear is which fields really denotes the cpu seconds/minutes used. The manual pages I have read say the 'cpu' column is for seconds burned, however there is alo the 'cp' column displayed with -m - and they can show different totals. For example:

When I use the -m flag, I get

 $sa -m | grep username
 username 14944      65.53re      29.90cp     5308k

When I use the -u flag and total up the column for 'cpu', I get the following:

 sa -u |grep username|awk 'BEGIN{TOTAL=0}{TOTAL=TOTAL+$2}END{print TOTAL}'

Can anybody help me understand the difference between the 'cp' and 'cpu' columns in these two different modes?


  • @epic9x - I updated my answer since I didn't think my first one was helpful.
    – Patrick R
    Jan 30, 2010 at 18:25

1 Answer 1


Let me use an example to help explain what your results above show:

First: I created a bash script that I ran as the user patrickr which was meant to put enough load on the system to be noticeable.

#this file is named loop_script.sh
for i in {1..5000}
   echo "Welcome $i times"

Second: I uninstalled and then reinstalled acct so that my files in /var/log/acct would be fresh. Create a copy of the /var/log/acct/pacct file so that in the future you can easily truncate the file with a properly formatted file (you can't just delete and recreate the file - sa will stop working if you do that). Note that this file is a log of all commands on the system and as far as I can tell there is no way to pull parts on the log based on time periods.

Third: I then ran this script twice as patrickr

patrickr@hostname:~$ bash loop_script.sh

I'll give you the results and then I'll explain them:

Ran as root (or any user other that patrickr) After first loop as patrickr:

**sa -m**
                            24       0.09re       0.03cp         0avio       894k
root                        22       0.07re       0.02cp         0avio       853k
patrickr                    2       0.02re       0.01cp         0avio      1336k

**sa -u |grep patrickr**

patrickr   0.38 cpu     1336k mem      0 io bash             

After second loop as patrickr:

**sa -m**
                            30       0.09re       0.03cp         0avio       850k
root                        27       0.07re       0.02cp         0avio       814k
patrickr                    3       0.02re       0.01cp         0avio      1178k

**sa -u |grep patrickr**

patrickr   0.38 cpu     1336k mem      0 io bash            
patrickr   0.35 cpu     1336k mem      0 io bash            
patrickr   0.00 cpu      863k mem      0 io ls  (I happened to also run ls at patrickr)

**sa -u**

The results returned 106 results for a total of 2.86cpu that averaged to 0.03cp

Here's what you're seeing:

sa -m is showing averages for the all the activity for this server overtime. This file grows larger over time as more commands run.

sa -u | grep patrickr is showing the sum of the system and user time in cpu minutes for specific commands.

Running: sa -u |grep patrickr|awk 'BEGIN{TOTAL=0}{TOTAL=TOTAL+$2}END{print TOTAL}'

Will give you a combined total for user patrick but the sa -m command is actually giving you averages. Take a look at the memory values is you need a second example. They're averaged too.

If I add the three results listed above for patrickr, .35 + .37 + .0 and divide by 106 and round to the to the nearest hundredth I'll get 0.01cp.

The result of 0.01cp is the average load of user patrickr on the system in comparison to all load on the system from the time that the acct application was installed (ie since the file /var/log/acct/pacct started keeping track).

Output Fields
cpu   -  sum of system and user time in cpu minutes
re    -  actual time in minutes
k     -  cpu-time averaged core usage, in 1k units
k*sec -  cpu storage integral (kilo-core seconds)
u     -  user cpu time in cpu minutes
s     -  system time in cpu minutes

A good resource that will help you is at beginlinux.com (original link found here).

  • I just wanted to apologize for the incredible delay on saying thank you for this response, this was a fantastic resource for me, and I was remiss in not saying so!
    – epic9x
    Aug 19, 2010 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.