3

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

Sid
  • 10,503
  • 10
  • 46
  • 47
Mark
  • 63
  • 1
  • 2
  • 6

1 Answers1

2

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]
Martin Owens -doctormo-
  • 19,860
  • 4
  • 63
  • 103
  • 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