2015-10-04 39 views
0

我有以下bash脚本。bash脚本中的SIGINT

#!/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 

我怎么能发送SIGINT信号,我infiniteProgramm

回答

1

第一:在后台运行infiniteProgram:

infiniteProgram -someParameters & 

二:从$检索其PID!

pid=$! 

第三:杀了它。

sleep 10 
kill -2 $pid 

2对应于SIGINT,看到kill -l对于所有信号的列表。