给定一个脚本,该脚本echo在接收到SIGSTOP或SIGHUP信号时:
$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)
发生了什么?