【发布时间】:2014-04-05 03:55:17
【问题描述】:
我有两个脚本:
### firstScript.sh ###
trap 'kill $pid;' SIGINT
for ((i=1; i<=10; i++))
do
echo "$i x $1 = `expr $i \* $1`"
sleep 10 &
pid=$!
wait $!
done
还有:
### secondScript.sh ###
./firstScript.sh 5 &
pid=$!
echo $pid
ps
for (( i=0; i<8; i++))
do
kill -2 $pid
sleep 3
done
第二个脚本将在后台模式下调用第一个脚本并每 3 秒向它发送一个 SIGINT 信号。但是,它根本不起作用。
我尝试使用./firstScript.sh 5 & 在后台运行第一个脚本,并使用kill -2 %1 或kill -2 <pid> 发送信号(在创建第一个脚本后观察到pid),它们都运行良好。
但是,我无法通过脚本做到这一点。
感谢任何帮助。
【问题讨论】:
-
trap 'kill $pid;' SIGINT在第一个脚本中,但它会杀死哪个pid? -
$pid 是休眠进程的PID