Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

4 Answers 4

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

share|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
add comment

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.
share|improve this answer
add comment

Try this:

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

Not quite what you're looking for, but sometimes a process is run by it's own user, like apache2 is often run by user www-data.

You can use that to limit top's output to only the processes by that user, effectively only showing apache2 processes by using this command:

top -u www-data
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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