I'm run top and I want to always see java/tomcat/redis/mysql/mongo, is that possible?
Asked
Active
Viewed 2.9k times
4 Answers
23
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

user9517
- 115,471
- 20
- 215
- 297
-
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. – user9517 Dec 23 '11 at 23:08
-
1A 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 : http://stackoverflow.com/questions/12075591/top-c-command-in-linux-to-filter-processes-listed-based-on-processname – MaasSql Dec 01 '16 at 17:09
-
1After 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 01 '16 at 17:18
6
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

DanMan
- 161
- 1
- 4
5
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.
4
Try this:
alias mytop='echo $(sed "s/\([0-9]*\)/-p \1/g;s/^/top /" <(pgrep -d" " "java|redis|mysql|mongo"))'
mytop

Mircea Vutcovici
- 17,619
- 4
- 56
- 83