I need to detect when one of my background processes exits. Hence, I installed a trap. run_gui
and run_ai1
are simple exec
functions.
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
When I close the GUI, nothing happens. The echo foo
command is executed only if I press ctrl+c.
Why do I miss the SIGCHLD
?
Non-interactive shells don't enable job control by default. See if putting 'set -o monitor' at the beginning of the script produces the results you want.
Source: Chet Ramey , GNU Bash's maintainer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.