Examples of how to kill all child jobs when a shell script exits.
The remaining scripts in the root are variants of the
kill_child_jobs() function. The
script tests them all and generates the following output showing which
version of the
kill_child_jobs() function works in each shell:
Legend: ∞=script does not halt (after 1 second timeout) X=disown unsupported by shell ☠=all children killed 🏃=all children still running ✔️=expected result (job killed, disowned child alive) bash sh ash dash zsh ksh all.sh ✔️ X☠ X☠ X☠ ✔️ ☠ bash.sh ✔️ X🏃 ∞X☠ X🏃 ✔️ ☠ dash.sh ✔️ X☠ X☠ X☠ 🏃 ☠ noop.sh 🏃 X🏃 X🏃 X🏃 🏃 🏃 pkill-P.sh ☠ X☠ X☠ X☠ ☠ ☠ zsh.sh ∞✔️ X🏃 ∞X☠ X🏃 ✔️ ☠