【发布时间】:2011-04-13 00:26:33
【问题描述】:
在子/后台进程中运行时,我无法捕获信号。
这是我的简单 bash 脚本:
#!/bin/bash
echo "in child"
trap "got_signal" SIGINT
function got_signal {
echo "trapped"
exit 0
}
while [ true ]; do
sleep 2
done
当运行这个和以后做
kill -SIGINT (pid)
一切正常,打印trapped 并退出。
现在,如果我从这样的父脚本启动相同的脚本:
#!/bin/bash
echo "starting the child"
./child.sh &
那么孩子就不再捕获信号了....?
改用 SIGTERM 而不是 SIGINT 后,它似乎工作正常...?
【问题讨论】:
标签: bash signals child-process sigint bash-trap