Recent Changes - Search:

Softwares

.

Display-running-processes-sorted-by-memory-usage


Display the top ten running processes - sorted by memory usage

ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT.

ps aux | sort -nk +4 | tail


or 


ps -eo rss,vsz,pid,cputime,cmd --width 100 --sort rss,vsz | tail --lines 10

ubuntu@server3:~$ ps aux | sort -nk +4 | tail
ubuntu    1537  0.1  1.9 253948 15092 ?        Sl   12:13   0:00 /usr/lib/gnome-panel/w
ubuntu    1545  0.0  1.9 279028 15112 ?        Sl   12:13   0:00 /usr/lib/indicator-
ubuntu    1302  0.1  2.0 323316 16488 ?        Sl   12:13   0:00 gnome-panel
ubuntu    1374  0.0  2.2 119316 17636 ?        Sl   12:13   0:00 /usr/bin/python 
ubuntu    1705  0.5  2.2 265060 17580 ?        Sl   12:15   0:02 gnome-terminal
ubuntu    1295  0.1  2.9 442536 23388 ?        Sl   12:13   0:00 nautilus
ubuntu    1658  0.0  2.9 237088 23152 ?        S    12:13   0:00 /usr/bin/python 
mysql      916  0.0  3.0 170128 23960 ?        Ssl  12:13   0:00 /usr/sbin/mysqld

ps help


$ ps --help
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty
*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
                    ********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy

Example:

etime ELAPSED elapsed time since the process was started, in the form [[DD-]hh:]mm:ss.


ubuntu@server3:~$ ps -eo etime,rss,vsz,pid,cputime,cmd --width 100 --sort rss,vsz | head -n 1
       ELAPSED   RSS    VSZ   PID     TIME CMD
ubuntu@server3:~$ ps -eo etime,rss,vsz,pid,cputime,cmd --width 100 --sort rss,vsz | tail --lines 10
      03:42 15188 325268  1312 00:00:00 nm-applet --sm-disable
      03:42 16488 323316  1302 00:00:00 gnome-panel
      01:55 17580 265060  1705 00:00:00 gnome-terminal
      03:41 17636 119316  1374 00:00:00 /usr/bin/python /usr/bin/zeitgeist-daemon
      03:12 23152 237088  1658 00:00:00 /usr/bin/python /usr/share/system-config-printer/applet.py
      03:42 23388 442536  1295 00:00:00 nautilus
      03:47 23960 170128   916 00:00:00 /usr/sbin/mysqld
      03:38 37244 123496  1549 00:00:01 /usr/bin/ruby1.8 /usr/bin/puppet master --masterport=8140
      03:48 54816 154496   826 00:00:02 /usr/bin/X :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-t
      01:51 173432 775488 1765 00:00:25 /usr/lib/firefox-4.0/firefox-bin
ubuntu@server3:~$ 


Edit - History - Print - Recent Changes - Search
Page last modified on December 14, 2012, at 11:14 AM