【问题标题】:SIGINT in bash scriptbash 脚本中的 SIGINT
【发布时间】:2015-10-04 21:59:24
【问题描述】:

我有以下 bash 脚本。

#!/bin/bash
while :
do
    sleep 2
    infiniteProgramm -someParametrs
    sleep 10
    #in this line I need to stop my infiniteProgramm with bash command (SIGINT) (like Ctrl+C, but automatic)
    clear
done

如何向我的infiniteProgramm 发送SIGINT 信号?

【问题讨论】:

    标签: linux bash signals


    【解决方案1】:

    首先:在后台运行infiniteProgram:

    infiniteProgram -someParameters &
    

    第二步:从 $! 中检索它的 PID。

    pid=$!
    

    第三:杀死它。

    sleep 10
    kill -2 $pid
    

    2 对应 SIGINT,所有信号列表见kill -l

    【讨论】: