Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Please help me to find a reliable way to compute (in a bash script) a jboss PID cpu load.

To be specific, I don't know how to aggregate /proc/[pid]/stat fields to obtain the load a specific process makes on a multiple cpu 64 bit env. Ubuntu.

Thanks a lot, Xander

share|improve this question

1 Answer 1

The tool that interprets the /proc/[pid]/stat information is ps, this tools allows you to get the cpu load of any single process on the system:

ps S -p [pid] -o pcpu=

To monitor using this command, you can use watch:

watch ps S -p [pid] -o pcpu=

This command outputs a percentage of total cpu use of the agregate of all child processes. If you want to see the tree of processes, use pstree:

pstree -p [pid]
share|improve this answer
1  
actually I belive "ps -Lp(pid) opcpu" does aggregate all pid's threads, isn't it? Unfortunately ps gives just snapshots of that cpu/thread load (it can't be used in real-time monitoring), and aggregating in the bash script all 300 threads in a jboss, by "cat"-ing all the file specific for that child pids it looks kind of unreliable. –  Mark Jan 28 '11 at 17:44
    
@xander - See my updates for further clarification. –  Martin Owens -doctormo- Jan 28 '11 at 17:53
    
thanks for the reply. I used the ps application and compared with top -d 1 -p [pid] output. While top updates the load, (like 30% 33% 37% 31%) ps returns a static percent (like 33% 33% 33% 33% etc...), just like a snapshot. Any solution? –  Mark Jan 28 '11 at 18:03
    
What happens if you run ps in one window and top in another? –  Martin Owens -doctormo- Jan 28 '11 at 19:25

Your Answer

 
discard

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.