Examples of how to kill all child jobs when a shell script exits.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Daniel Perelman 0e4167e786 Fix typo. 10 months ago
test Fix extra newlines in output. 11 months ago
LICENSE Initial commit 11 months ago
README.md Updated README. 11 months ago
all-full-example.sh Improved full example and added pkill-P version. 11 months ago
all.sh Remove outdated comment. 11 months ago
bash.sh Fix comments. 11 months ago
dash.sh Fix comments. 11 months ago
noop.sh kill_child_jobs() implementation that does nothing for testing. 11 months ago
pkill-P-full-example.sh Fix typo. 10 months ago
pkill-P.sh Fix typo. 10 months ago
zsh.sh Fix comments. 11 months ago

README.md

kill-child-jobs

Examples of how to kill all child jobs when a shell script exits.

all-full-example.sh starts some jobs, disowns one of them, and kills all jobs when it exits. pkill-P-full-example.sh does the same except it kills all child processes when it exits.

The remaining scripts in the root are variants of the kill_child_jobs() function. The test/test-all.sh 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🏃	✔️	☠