杀死多个名为my_server的进程:
PIDS=`ps -ef | grep my_server | awk '{print $2}'`
for pid in $PIDS
do
kill -9 $pid
done
判断主从进程my_server是否存在,存在就杀死所有my_server进程
#!/bin/sh
isServerExist=`ps -ef|grep -m 1 my_server|grep -v "grep"|wc -l`
if [ "$isServerExist" = "0" ]; then
echo "my_server not found"
# exit;
elif [ "$isServerExist" = "1" ]; then
pid=`ps -ef|grep -m 1 my_server | awk '{print $1}'`
kill $pid
fi
注:
grep -v "grep" 去掉grep进程,wc -l 返回行数