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.

  • 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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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