trap
From: https://www.jianshu.com/p/b81783fee7da
#!/usr/bin/bash
self=$0
process=$1
if [[ -z "$process" ]]; then
echo
echo " ---> Please specify a process for test!"
exit -1
fi
function myecho {
echo
echo "[+] $1"
$1
}
trap 'onCtrlC' INT
function onCtrlC() {
ps -ef | grep $process | awk '{print $2}' | xargs kill -9
ps -ef | grep $self | awk '{print $2}' | xargs kill -9
}
# start from here
#myecho "aocl diagnose"
n=0
while true;do
sleep 1
echo
date | xargs echo "test $n: "
./$process &
n=$[n+1]
sleep 3
myecho "kill -9 $!"
done
网友评论