Displays user-defined ps output and pidstat output about the top CPU or MEMory users.

for i in $(ps -eo pid,pmem,pcpu| sort -k 3 -r|grep -v PID|head -10|awk '{print $1}');do diff -yw <(pidstat -p $i|grep -v Linux) <(ps -o euser,pri,psr,pmem,stat -p $i|tail);done
It grabs the PID's top resource users with $(ps -eo pid,pmem,pcpu| sort -k 3 -r|grep -v PID|head -10) The sort -k is sorting by the third field which would be CPU. Change this to 2 and it will sort accordingly. The rest of the command is just using diff to display the output of 2 commands side-by-side (-y flag) I chose some good ones for ps. pidstat comes with the sysstat package(sar, mpstat, iostat, pidstat) so if you don't have it, you should. I might should take off the timestamp... :|
Sample Output
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	builder    0  19 127652 510608 205612 10.0 Sl
04:47:32 PM      2050    3.70    0.51    0.00    4.21     1   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	root       0  19 15690  62760 38920  1.8 Rs+
04:47:32 PM      1655    0.93    2.40    0.00    3.33     1   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	builder    0  19 46361 185444 41000  1.9 Sl
04:47:32 PM      8461    1.34    0.53    0.00    1.87     0   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	builder    0  19 61604 246416 37580  1.8 Sl
04:47:32 PM      1846    1.67    0.66    0.00    2.33     0   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	root       0  19  5637  22548  7016  0.3 S
04:47:32 PM      2148    1.14    0.39    0.00    1.53     1   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	104        0  19   768   3072  1312  0.0 Ss
04:47:32 PM       801    0.80    0.34    0.00    1.14     0   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	root       0  19  3267  13068  6992  0.3 S
04:47:32 PM      2152    0.70    0.14    0.00    0.84     1   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	builder    -   0 11985  47940 38568  1.8 SNl
04:47:32 PM      2029    0.47    0.03    0.00    0.50     1   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	root       0  19  4665  18660  1120  0.0 Ssl
04:47:32 PM      1143    0.09    0.33    0.00    0.43     0   <
							      |	EUSER     NI PRI    SZ    VSZ   RSS %MEM STAT
04:47:32 PM       PID    %usr %system  %guest    %CPU   CPU   |	root       -  90     0      0     0  0.0 S
04:47:32 PM      2381    0.00    0.14    0.00    0.14     1   <

1
2012-02-16 20:54:32

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: