Human readable memory usage in Linux per process

LinuxI like to tune my VPS to use as little memory as possible. Not because I really want to; but because I just don’t have the money to spend on a 2+ GB RAM VPS and I would like to run Jira.

In order to do this I keep a close eye on the processes running and how much memory each takes.

For this I found (and tweaked) the following bash command (originally found here):

ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }'

This command will output every process and its memory usage in human readable (thus megabytes) format. For your convenience it is sorted by memory size descending (from highest to lowest).

An example of its use:

mvriel@naenius:~$ ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }'
0.00 Mb COMMAND
116.18 Mb /usr/sbin/mysqld
11.58 Mb /usr/sbin/apache2 -k start
11.58 Mb /usr/sbin/apache2 -k start
11.58 Mb /usr/sbin/apache2 -k start

(I am sure I can tune the above to use less memory; this is merely an example)

I hope it will be as useful to you as it is to me,

Until next time!


Comments

7 responses to “Human readable memory usage in Linux per process”

  1. “<” should be “<", I think the blog engine double encoded that.

    Tyrael

  2. “&lt;” should be “<"

    Tyrael

  3. Thank you for noticing! It appears that the Geshi plugin which I use does an extra encoding. I have fixed the issue and it should show up all right now.

  4. sharjeel Avatar
    sharjeel

    wowwww

  5. Good one. could get the entire list of processes with the amount consumed.

  6. Great post! Solved a huge problem for me today!

    Thanks!

  7. It would be good to see a way to grep out a particular item and add up the memory usage, for instance for one particular PHP FPM pool.