[英]SIGCHLD not delivered when a process exits
我需要检测我的一个后台进程何时退出。 因此,我安装了一个陷阱。 run_gui
和run_ai1
是简单的exec
函数。
run_gui & gui_pid=$!
run_ai1 & ai1_pid=$!
trap 'echo foo' SIGCHLD
while true; do
echo "Started the loop"
while true; do
read -u $ai1_outfd line || echo "Nothing read"
if [[ $line ]]; then
: # Handle this
fi
done
while true; do
read -u $gui_outfd line || echo "nothing read"
if [[ $line ]]; then
: # Handle this
fi
done
done
当我关闭GUI时,没有任何反应。 只有按ctrl + c,才会执行echo foo
命令。
为什么我会错过SIGCHLD
?
默认情况下,非交互式shell不启用作业控制。 看看在脚本开头放置'set -o monitor'是否会产生你想要的结果。
来源: Chet Ramey ,GNU Bash的维护者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.