Hi I have a problem running watch command like this:
watch cat /proc/$(ps ax | grep processname | grep -v grep | awk '{print $1}')/status
The command works when I start it. However, then I restart the process being watched and the watch command still uses old process id. I want it to refresh the process id and show the status of a new process with the same name. The part $(ps ax | grep processname | grep -v grep | awk '{print $1}')
is obviously ran only at the start. How can I make it to be reevaluated every time the watch refreshes the output?
I would not like to put the cat command in a bash script and run that script from watch.
pgrep
.ps | grep | grep -v | awk
"works" but there are many better ways - evenps ax | awk '/processname/ && ! /awk/ {print $1}'
is better. orps -o pid -C processname
.