After searching so many answers on StackOverflow, I did not see an answer to fit my needs.
That is, so that the top command continues to be updated with the given keyword, and we do not need to create CTRL + C / top again and again when new processes appear.
So I'm doing a new one ...
Here is the version without restarting.
__keyword=name_of_process; (while :; do __arg=$(pgrep -d',' -f $__keyword); if [ -z "$__arg" ]; then top -u 65536 -n 1; else top -c -n 1 -p $__arg; fi; sleep 1; done;)
Change __keyword and it should work. (Verified by Ubuntu 2.6.38)
2.14.2015 added: Invalid part of the system workload with the above code. For people who care about the "average load":
__keyword=name_of_process; (while :; do __arg=$(pgrep -d',' -f $__keyword); if [ -z "$__arg" ]; then top -u 65536 -n 1; else top -c -n 1 -p $__arg; fi; uptime; sleep 1; done;)
Val Dec 26 '14 at 6:54 2014-12-26 06:54
source share