I'm running several background processes in my script
run_gui()
{
exec ... # the real commands here
}
The functions run_ai1(), run_ai2
are analogous.
Then I run the functions and do the needed piping
run_gui &
run_ai1 &
run_ai2 &
while true; do
while true; do
read -u $ai1_outfd line || echo "Nothing read"
if [[ $line ]]; then
: # processing
fi
done
sleep $turndelay
while true; do
read -u $ai2_outfd line || echo "nothing read"
if [[ $line ]]; then
: # processing
fi
done
sleep $turndelay
done
If any of those three processes exits, I want to check their exit codes and terminate the rest of the processes. For example, if run_ai2
exits with exit code 3, then I want to stop the processes run_ai1
and run_gui
and exit the main script with exit code 1. The correct exitcodes for the different backgrounds processes may differ.
The problem is: how can I detect it? There's the command wait
but I don't know in advance which script will finish first. I could run wait
as a background process - but it's becoming even more clumsy.
Can you help me please?
SIGCHLD
comes far from what I described in here. Either the process doesn't exit at all (and doesn't react to SIGINT) or exits prematurely. – marmistrz