1
0
Examples of how to kill all child jobs when a shell script exits. https://aweirdimagination.net/2020/06/28/kill-child-jobs-on-script-exit/
Go to file
2020-07-04 20:38:09 -07:00
test Fix extra newlines in output. 2020-05-27 13:42:42 -07:00
all-full-example.sh Improved full example and added pkill-P version. 2020-05-27 13:34:26 -07:00
all.sh Remove outdated comment. 2020-05-27 13:46:31 -07:00
bash.sh Fix comments. 2020-05-27 13:49:48 -07:00
dash.sh Fix comments. 2020-05-27 13:49:48 -07:00
LICENSE Initial commit 2020-05-27 07:57:49 +00:00
noop.sh kill_child_jobs() implementation that does nothing for testing. 2020-05-27 13:01:41 -07:00
pkill-P-full-example.sh Fix typo. 2020-07-04 20:38:09 -07:00
pkill-P.sh Fix typo. 2020-07-04 20:38:09 -07:00
README.md Updated README. 2020-05-27 13:38:14 -07:00
zsh.sh Fix comments. 2020-05-27 13:49:48 -07:00

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🏃	✔️	☠