Linux shell脚本实现kill进程

shell脚本实现kill tomcat进程

以我本地通过/home/tomcat/bin/startup.sh启动的tomcat进程为例:

# cat test.sh

#!/bin/sh

ps -aux | grep tomcat | grep bootstrap | grep -v grep | awk '{print $2}' | while read pid

do
    echo "tomcat is running, to kill bootstrap pid=$pid"
    kill -9 $pid
    echo "kill result: $?"
done

如果进程存在:

# ./test.sh 

tomcat is running, to kill bootstrap pid=27533
kill result: 0

如果进程不存在:

# ./test.sh
#



你可能感兴趣的:(Linux)