ps -ef|grep Dflag=${APP_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill "}{printf "%s ", $2}'|bash echo "${APP_NAME} stopped!"
illustrate:
ps -ef [Get the currently active process]
grep abc [contains the string abc]
grep -v abc [does not contain the string abc]
ps -ef|grep Dflag=${APP_NAME}|grep -v grep|grep -v tail [Filter values with the string "Dflag=xxx" in all active processes without "grep" and without " tail”]
awk 'BEGIN {printf "kill "} {printf "%s ", $2}'|bash [print kill + process number [the second column in the list displayed by ps -ef is the process number] For example, if the process number is 11891, it will Output kill 11891 The last line of the command |bash means to execute kill 11891, that is to kill the process, if you do not write |bash, it will only print and not execute]