How to know which processes uses the most resources

There are times where some processes use too much resources. You can use “ps aux” to get a list of all the processes that are currently running. But what about having them sorted? Here is one way. This works in Ubuntu Linux.

Top 10 % CPU usage

ps aux|sort -nr -k3|grep -v USER|head -10

Top 10 % Memory usage

ps aux|sort -nr -k4|grep -v USER|head -10

The following is the sample output for Top 10 % memory usage:

briecheese ~: ps aux|sort -nr -k4|grep -v USER|head -10
www-data  3883  2.9 14.1 107052 37176 ?        S    11:44   1:46 /usr/bin/php-cgi
www-data  3882  2.9 13.8 107664 36264 ?        S    11:44   1:46 /usr/bin/php-cgi
www-data  3881  1.2 13.2 106768 34688 ?        S    11:44   0:44 /usr/bin/php-cgi
www-data  3884  3.1 13.1 107244 34592 ?        S    11:44   1:54 /usr/bin/php-cgi
www-data  3879  1.1 11.8 106888 31160 ?        S    11:44   0:40 /usr/bin/php-cgi
www-data  3880  0.9  9.5  94232 25092 ?        S    11:44   0:34 /usr/bin/php-cgi
mysql     3659  3.5  6.9 277256 18200 ?        Sl   09:45   6:25 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root      4103  0.2  1.0  53468  2704 ?        Ss   12:44   0:00 sshd: me [priv]
me    4106  0.0  0.8  18128  2116 pts/0    Ss   12:44   0:00 -bash
www-data  3875  0.0  0.7  57440  1972 ?        S    11:44   0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

Percentage memory usage is the 4th column. This is useful when you need a quick overview of what’s consuming the most memory. [Thanks U-Zyn]

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>