0

I monitor several processes with i.e. '#top -p 22055,21995' But there are many of them all starting with fwk* i.e. fwk3_dev, fwk5_dev

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                        
22055 admin      0 -20  832m 302m  41m S   20  2.5  14973:53 fwk3_dev                                                                                       
21995 admin      0 -20  834m 304m  41m S   14  2.6  10179:55 fwk5_dev 

How I can monitor using regex name of process fwk* I mean all processes with starting from 'fwk'?

0

top will not do this by itself, but you could write a simple shell script which runs top in batch mode (the -b option), filtering that using grep, and in a loop. It would not be interactive.

For example

while :; do clear; top -b -n 1 |grep ' fwk' ;sleep 1; done

grep does recognize regular expressions, given the -E option. But your example can be handled with just a leading blank and "fwk" (unless you happen to have a user with the same name).

Some versions of top may need a different option (such as -d) to run just once in batch mode.

1
# first generate a comma-separated list of matching PIDs
pids=$(ps a -o pid,args | awk '/[f]wk/ {print $1}' | xargs | sed -e 's/ /,/g')
# then run top with that list
top -p $pids

NOTE: if any fwk* processes are started in the short time between generating the list and running top, they will not be included in the display.

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.