How to sort the Linux 'ps' command output by RAM

With this site hosted on a virtual server, I'm fighting quite a battle over memory use with the new LAMP architecture in place. As I try to learn more about which applications are using the most memory, I ran into this cool ps command last night that sorts the ps output by memory use, specifically by the rss field:

ps aux --sort:rss

Here's the important output from that command:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
nobody    9518  0.0  0.0  14776  6748 ?        S    Apr11   0:00 httpd -k start
nobody    9427  0.0  0.0  14776  6752 ?        S    Apr11   0:00 httpd -k start
nobody    9428  0.0  0.0  14776  6752 ?        S    Apr11   0:00 httpd -k start
nobody    9475  0.0  0.0  14776  6756 ?        S    Apr11   0:00 httpd -k start
root      9380  0.0  0.0  14760  6864 ?        Ss   Apr11   0:00 httpd -k start
nobody    9426  0.0  0.0  15232  7928 ?        S    Apr11   0:00 httpd -k start
nobody    9447  0.0  0.0  15240  7932 ?        S    Apr11   0:00 httpd -k start
nobody    9471  0.0  0.0  15240  7940 ?        S    Apr11   0:00 httpd -k start
nobody    9394  0.0  0.0  15256  7964 ?        S    Apr11   0:00 httpd -k start
nobody    9392  0.0  0.0  15260  7968 ?        S    Apr11   0:00 httpd -k start
nobody    9472  0.0  0.0  15232  7968 ?        S    Apr11   0:00 httpd -k start
nobody    9390  0.0  0.0  15480  8228 ?        S    Apr11   0:00 httpd -k start
nobody    9430  0.0  0.0  23096 15892 ?        S    Apr11   0:00 httpd -k start
nobody    9474  0.0  0.0  24116 16876 ?        S    Apr11   0:00 httpd -k start
nobody    9429  0.0  0.0  24356 17160 ?        S    Apr11   0:00 httpd -k start
nobody    9391  0.0  0.0  24380 17184 ?        S    Apr11   0:01 httpd -k start
nobody    9516  0.0  0.0  24628 17192 ?        S    Apr11   0:00 httpd -k start
nobody    9515  0.0  0.0  24628 17208 ?        S    Apr11   0:00 httpd -k start
nobody    9414  0.0  0.0  24612 17216 ?        S    Apr11   0:00 httpd -k start
nobody    9393  0.0  0.0  25144 17760 ?        S    Apr11   0:00 httpd -k start
nobody    9511  0.0  0.0  25260 17932 ?        S    Apr11   0:00 httpd -k start
mysql    11519  0.0  0.1 129064 25628 ?        Sl   Apr10  13:56 mysqld --basedir=

I don't yet know where the Apr10 and Apr11 references are coming from -- it's currently August 26th -- but having the output of the ps command sorted like this is very nice. I'm so used to using the sort command in a pipeline that I often forget that a command like ps may have its own sorting capability. Again, very nice.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.