Viewing Top Processes according to cpu, mem, swap size, etc.

command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'
I've wanted this for a long time, finally just sat down and came up with it. This shows you the sorted output of ps in a pretty format perfect for cron or startup scripts. You can sort by changing the k -vsz to k -pmem for example to sort by memory instead. If you want a function, here's one from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html aa_top_ps(){ local T N=${1:-10};T=${2:-vsz}; ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -${T} -A|sed -u "/^ *PID/d;${N}q"; }
Sample Output
[17764:17759 0:782] 02:35:26 Tue May 18 [bhudda@askapache.com:/dev/pts/0 +1] ~
(1:782)$ command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'
13832 mysql    mysql      188096   178696  47024  47300     4.5     0.9 01:01:26 stext   0 Sl   4 mysqld          /mysqld --basedir=/
14159 named    named      134088   127412  33522  25488     2.4     0.0 00:00:37 rt_sig  0 Ssl  5 named           /named -u named -t /chroot
32291 root     aaaa        79884    76464  19971  77276     7.3     1.3 00:23:42 stext   0 Ss   5 screen          SCREEN -a -A -R -S sh-askapache
29869 nobody   nobody      10736     3268   2684   3904     0.3     0.0 00:00:00 semtim  0 S    5 httpd           /apache/bin/httpd -k start -DSSL
11522 nobody   nobody      10640     3172   2660   4004     0.3     0.1 00:00:00 semtim  0 S    5 httpd           /apache/bin/httpd -k start -DSSL
23801 nobody   nobody      10640     3172   2660   4004     0.3     0.0 00:00:00 semtim  0 S    5 httpd           /apache/bin/httpd -k start -DSSL
11403 nobody   nobody      10616     3148   2654   3832     0.3     0.0 00:00:00 semtim  0 S    5 httpd           /apache/bin/httpd -k start -DSSL
11487 nobody   nobody      10616     3148   2654   3980     0.3     0.0 00:00:00 semtim  0 S    5 httpd           /apache/bin/httpd -k start -DSSL
29828 nobody   nobody      10616     3148   2654   3984     0.3     0.1 00:00:00 stext   0 S    5 httpd           /apache/bin/httpd -k start -DSSL

What Others Think

I use this: ps axo pid,user,vsz,state,pcpu,pmem,stime,time,comm,args --sort vsz shows all running processes (incl daemons), sorts in ascending order
piccobello · 523 weeks and 5 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: