我需要检测我的后台进程何时退出。因此,我安装了一个陷阱。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时,才会执行ctrl+c命令。
为什么我错过了SIGCHLD
发布于 2016-05-31 18:36:20
默认情况下,非交互式shell不启用作业控制。查看在脚本开头放置“set -o监视器”是否会产生您想要的结果。
资料来源:切特·雷米,GNU Bash的维护者
https://stackoverflow.com/questions/37552755
复制相似问题