Issue
top -c
Top lists all the processes, there are good options to filter the processes by username by using the option -u but I am wondering if there is any easy way to filter the processes based on processname listed under COMMAND column of the top output.
For Example I would want like top -some option -substring of processname and top displays pids only having this substring in its command name
Solution
Using pgrep to get pid's of matching command lines:
top -c -p $(pgrep -d',' -f string_to_match_in_cmd_line)
top -p
expects a comma separated list of pids so we use -d','
in pgrep. The -f
flag in pgrep makes it match the command line instead of program name.
Answered By - perreal