2015-10-04 40 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對於所有信號的列表。