October 2024
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories

October 2024
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

memory usage in Linux per process

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:

test@rmohan.com:~$ 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,

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>