按进程名终止进程
按进程名终止进程
#!/bin/bash echo "Terminate process(es) has " $1 " in name." echo "Self pid " $$ echo "Self name " $0 pids=$(ps -ef | grep $1 | grep -v grep | grep -v $0 | awk '{print $2}') pid_array=($pids) for x in ${pid_array[@]}; do echo "pid: " $x kill $x done echo "Search for $1 again" ps -ef | grep $1 echo "Finished."