Reputation: 6392
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
?
Upvotes: 3
Views: 1060
Reputation: 88601
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
Upvotes: 5