Hey im writing a bash script that launches a bunch of subprocesses, and when the process of the script is terminated all subprocesses and possible children of those subprocesses will be terminated
#!/bin/bash
trap "kill \$(pgrep -P $$)" EXIT
command0 &
command1 &
etc...
wait
This works fine when i run the script by itself. Children processes are propperly cleaned up.
However, when running this script as a subprocess itself:
./self_terminating.bash &
sleep 10 # let subprocesses do their thing
kill $!
Children processes are not killed propperly.
Some good samaritan wanna lend me hand?