相关疑难解决方法(0)

为什么我的陷阱没有触发?

给定一个脚本,该脚本echo在接收到SIGSTOPSIGHUP信号时:

$cat test.sh 
function clean_up {
    echo "cleaning up!"
}

echo 'starting!'

trap clean_up SIGSTOP SIGHUP

sleep 100
Run Code Online (Sandbox Code Playgroud)

我在后台运行它:

$./test.sh > output &
[4] 42624
Run Code Online (Sandbox Code Playgroud)

然后,我用-1,即SIGHUP杀死了它

$kill -1 42624
Run Code Online (Sandbox Code Playgroud)

但是trap没有按我预期的那样工作,即该output文件cleaning up!的内容没有。

$cat output 
starting!
Run Code Online (Sandbox Code Playgroud)

发生了什么?

shell signals trap

4
推荐指数
2
解决办法
6958
查看次数

标签 统计

shell ×1

signals ×1

trap ×1