Bash 进程退出时未传递SIGCHLD

Bash 进程退出时未传递SIGCHLD,bash,bash-trap,Bash,Bash Trap,我需要检测我的一个后台进程何时退出。因此,我安装了一个陷阱run\u gui和run\u 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"

我需要检测我的一个后台进程何时退出。因此,我安装了一个陷阱
run\u gui
run\u 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”放在脚本的开头会生成 你想要的结果


资料来源:,GNUBash的维护者

这不会改变任何事情。
读取
正在等待输入,这有关系吗…?我的沙邦是
#/bin/bash-m
。因此,我建议不要这样测试它。结果完全相同。这个简单的示例适用于GNU bash 4.2.8:
set-o监视器;陷阱“回声你好”信号;sleep 3&
在注释完
read
行后,问题似乎消失了。看来
read
正在阻止一切,包括陷阱。我从主脚本中初始化为读写并提供给
run\u gui的fd中读取