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!