Updated top ten memory utilizing processes (child/instance aggregation) now with percentages of total RAM

TR=`free|grep Mem:|awk '{print $2}'`;ps axo rss,comm,pid|awk -v tr=$TR '{proc_list[$2]+=$1;} END {for (proc in proc_list) {proc_pct=(proc_list[proc]/tr)*100; printf("%d\t%-16s\t%0.2f%\n",proc_list[proc],proc,proc_pct);}}'|sort -n |tail -n 10
Prints the top 10 memory consuming processes (with children and instances aggregated) sorted by total RSS and calculates the percentage of total RAM each uses. Please note that since RSS can include shared libraries it is possible for the percentages to add up to more that the total amount of RAM, but this still gives you a pretty good idea. Also note that this does not work with the mawk version of awk, but it works fine with GNU Awk which is on most Linux systems. It also does not work on OS X.
Sample Output
2584    cupsd                   0.25%
3096    tlsmgr                  0.30%
3624    getty                   0.35%
3948    nm-system-setti         0.38%
3968    gdm                     0.38%
4668    hald                    0.45%
6404    sshd                    0.61%
14716   apache2                 1.40%
22104   mysqld                  2.11%
33400   console-kit-dae         3.18%

3
By: d34dh0r53
2010-03-27 01:34:50

These Might Interest You

What Others Think

a gem
linuxrawkstar · 429 weeks and 1 day ago
I like it, but I want it reversed. I put "tac" at the end. TR=`free|grep Mem:|awk '{print $2}'`;ps axo rss,comm,pid|awk -v tr=$TR '{proc_list[$2]+=$1;} END {for (proc in proc_list) {proc_pct=(proc_list[proc]/tr)*100; printf("%d\t%-16s\t%0.2f%\n",proc_list[proc],proc,proc_pct);}}'|sort -n |tail -n 10 | tac
rthemocap · 429 weeks ago
Or, you can change "sort -n|tail -n 10" to "sort -nr|head -n 10" if you want it reversed. I added a column description by adding this line in front. printf "%-7s\t%-16s\t%-4s\n" RSS COMMAND RSS%;
beila · 427 weeks and 6 days ago
You need to change %0.2f% to %0.2f in the second awk, my system wouldn't run the command until I fixed it.
g0tmk · 341 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: