#!/bin/bash dir=$(dirname $(readlink -f "$0")) full=$(readlink -f "$0") name=$(basename $(readlink -f "$0")) cd $dir if [ "$1" != "runing" ] then rm -f run_tmp.sh echo "function mykill() { while : do killPid=\`ps -ef |grep \"\$1\" |grep -v grep | awk '{print \$2}'\` if [ \"\$killPid\" != \"\" ]; then killall -9 \$1 kill -9 \$killPid else break fi done }">>run_tmp.sh echo "rm -f $dir/run_tmp.sh">>run_tmp.sh echo "mykill \"$name\"">>run_tmp.sh echo "nohup sh $full runing &">>run_tmp.sh nohup sh $dir/run_tmp.sh & wait exit fi ps -ef|grep $name while : do echo "---ok---">>run.txt sleep 1 done