【发布时间】:2014-09-10 23:58:27
【问题描述】:
我希望无限循环继续运行,并且只是暂时被终止信号中断。我试过 SIGINT、SIGUSR1、SIGUSR2。所有这些似乎都停止了循环。我什至尝试过 SIGINFO,但 Linux 不支持。
#!/bin/bash
echo $$ > /tmp/pid # Save the pid
function do_something {
echo "I am doing stuff" #let's do this now, and go back to doing the thing that is to be done over and over again.
#exit
}
while :
do
echo "This should be done over and over again, but always wait for someething else to be done in between"
trap do_something SIGINT
while `true`
do
sleep 1 #so we're waiting for that other thing.
done
done
在从另一个脚本获得 INT 信号后,我的代码运行该函数一次,但之后再也不运行了。它停止了。
编辑:虽然我不小心把 en exit 放在了函数的末尾,但在 Stack Overflow 上,我并没有在我使用的实际代码中。无论哪种方式,它都没有任何区别。解决方案是 Tiago 描述的 SIGTERM。
【问题讨论】: