Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So basically I have multiple users on my system and I want to determine how much CPU time they spend while being logged in into their shell and running different commands. I have a script which knows the PID of the shell they are logged in with. I must be able to probe the value regularly so I can't simply run the shell in time(1) or something like that.

I have glanced at /proc/$pid - anyone knows of a good value (or combination of values) there I could use? Maybe there's some kernel module for this?

An acceptable solution to my problem would allow querying init (the process with pid = 1) and find the total CPU time the entire system has used so far.

share|improve this question
You just want to know how much CPU time they use or you want to limit it? Because resource quotas would help with the latter... – Bart Silverstrim Oct 3 '11 at 12:43
Do you want total CPU usage per user or for the whole system? – Iain Oct 3 '11 at 12:56
up vote 0 down vote accepted

Look at using cgroups to throttle and control activity on a per-user basis to a per-cpu basis. Once that is done you can use the cgroups statistics patch to generate the information you are looking for.

share|improve this answer
Thanks - cgroups solves my problem. – Hannes Landeholm Nov 13 '11 at 10:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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