我需要检测我的后台进程之一何时退出。因此,我安装了一个陷阱。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
Run Code Online (Sandbox Code Playgroud)
当我关闭 GUI 时,没有任何反应。该echo foo命令仅在我按 ctrl+c 时执行。
为什么我想念SIGCHLD?