美文网首页
2019-03-06 trap/Ctrl+C

2019-03-06 trap/Ctrl+C

作者: 七点水Plus | 来源:发表于2019-03-06 21:35 被阅读0次

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

相关文章

  • 2019-03-06 trap/Ctrl+C

    trap From: https://www.jianshu.com/p/b81783fee7da

  • Linux trap

    trap是一个shell内建命令,它用来在脚本中指定信号如何处理。比如,按Ctrl+C会使脚本终止执行,实际上系统...

  • bash 中冷门但非常有用的命令: trap

    trap 属于bash的内置命令,所以查看帮助用: help trap, 如果用”man trap“则会跳出bas...

  • THE STORY

    What is "TRAP"? When we talk about trap something, someti...

  • pod install Abort trap: 6问题及解决方

    pod lib lint Abort trap: 6 pod install Abort trap: 6 如果你执...

  • pod install Abort trap: 6

    pod lib lint Abort trap: 6 pod install Abort trap: 6 如果你执...

  • gen_server的terminate使用

    process_flag(trap_exit,true)的理解: process_flag(trap_exit,t...

  • Fan Trap and Chasm Trap

    Fan Trap (扇形陷阱) When an entity has more than one 1:N rela...

  • Trap

    今天就和大家来说一说我理解的陷阱。 我理解的陷阱有很多。比如,他人给你设下的陷阱。和你自己设下的陷阱。和社会上的陷...

  • Trap

    One step two step three step Step by step shoulder by sho...

网友评论

      本文标题:2019-03-06 trap/Ctrl+C

      本文链接:https://www.haomeiwen.com/subject/dkrfpqtx.html