#!/bin/bash
BIN_NAME=$1
ps -ef|grep $BIN_NAME|grep -v grep
if [ $? -ne 0 ]; then
echo "process $BIN_NAME is not exist"
else
PID=$(ps -ef|grep $BIN_NAME|grep -v grep|awk '{print $2}')
$(kill -9 $PID)
if [ $? -ne 0 ]; then
echo "stop $BIN_NAME failed"
else
echo "stop $BIN_NAME success"
fi
fi
使用方法 假设脚本的名字叫stop.sh 程序的名字叫 main
./stop.sh main
会把所有名字叫main的进程全部kill,因此注意一定要输入全名,