Is it possible to filter top to show specific processes?
I'm run top and I want to always see java/tomcat/redis/mysql/mongo, is that possible?
Solution 1:
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
Solution 2:
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
Solution 3:
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.
Solution 4:
Try this:
alias mytop='echo $(sed "s/\([0-9]*\)/-p \1/g;s/^/top /" <(pgrep -d" " "java|redis|mysql|mongo"))'
mytop