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:

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.

pidstat” comes with “sysstat” (installed with “apt-get install sysstat“). Here is an article on pidstat:

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


Leave a Reply

Your email address will not be published. Required fields are marked *