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


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

  • 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
  • 1
    A note to future viewers - this method may not give you the data you are expecting. a) this method shows only processes running when top is started. Top's normal behavior is to show processes new since it began. b) the top manual I read says -p is limited to 20 process ids. see : stackoverflow.com/questions/12075591/… – MaasSql Dec 1 '16 at 17:09
  • 1
    After running top -c , hit o and write a filter on a column, e.g. to show rows where COMMAND column contains the string foo, write COMMAND=foo – MaasSql Dec 1 '16 at 17:18

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
  • Great! I was wondering how to list user specific processes – razor7 Mar 24 '16 at 18:38

Try this:

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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