Getting the heaviest RAM processes in Linux is pretty easy, getting RAM usage numbers is pretty easy to. However getting CPU usage numbers per process in Linux is harder to come by. For example, top and top -c only have precision to 0 decimal places. Where as ps can offer 0.x one decimal precision for cpu usage (read update below to see 0.xx, two decimal precision for cpu usage). Here it is
( echo "#### heaviest cpu ####" ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 2 | head echo "#### heaviest mem ####" ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 1 | head )
Here is the resource on that:
http://www.math-linux.com/linux/tip-of-the-day/article/find-out-biggest-cpu-memory-consuming-processes-with-ps-command
If you know of a better process let me know.
If you can show me a way to measure CPU on a linux box usage of a process over a given interval of time (instead of every second).
UPDATE: Looks like the program ive been looking for is pidstat. For those interested in how CPU usage is calculated check this stackoverflow page out.
http://stackoverflow.com/questions/1420426/calculating-cpu-usage-of-a-process-in-linux
“pidstat” comes with “sysstat” (installed with “apt-get install sysstat“). Here is an article on pidstat:
http://xmodulo.com/how-to-measure-average-cpu-utilization.html
This gives me the numbers I want but its only for a single process. I wish it could list it for all processes at once. Well it can, and here is how:
pidstat <interval seconds> # example: pidstat 5
For a single process you can do this:
pidstat <interval in seconds> -p <pid number> # example: pidstat 4 -p 2121