I'm run top and I want to always see java/tomcat/redis/mysql/mongo, is that possible?

link|improve this question

51% accept rate
feedback

3 Answers

You could to something like this

top -p `pgrep -d ',' "java|tomcat|redis|mysql|mongo"`

This gets pgrep to produce a comma separated list of pid's that are passed to top -p

link|improve this answer
Much simpler :) – Mircea Vutcovici Dec 23 '11 at 23:04
I was struggling to figure out how to find the process list for multiple process names till I saw how you did it. – Iain Dec 23 '11 at 23:08
feedback

Check man top manual page for more details about top utility...

Semms you need -p parameter

-p : Monitor PIDs as: -pN1 -pN2 ... or -pN1, N2 [,...]

        Monitor only processes with specified process  IDs.   This  option
        can  be given up to 20 times, or you can provide a comma delimited
        list  with  up  to  20  pids.   Co-mingling  both  approaches   is
        permitted.
link|improve this answer
feedback

Try this:

alias mytop='echo $(sed "s/\([0-9]*\)/-p \1/g;s/^/top /" <(pgrep -d" " "java|redis|mysql|mongo"))'
mytop
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.