top -c command in linux to filter processes listed based on processname
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.
It can be done interactively
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
If you just want some basic output this might be enough:
top -bc |grep name_of_process
You can add filters to top
while it is running. Just press the o key and then type in a filter expression.
For example, to monitor all processes containing the string "java", use the filter expression COMMAND=java
.
You can add multiple filters by pressing o again.
You can filter by user with u. Clear all filters with =.