2019-03-06 trap/Ctrl+C

2019-03-06  本文已影响0人  七点水Plus

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
上一篇 下一篇

猜你喜欢

热点阅读