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.
|
- #!/bin/sh
- set -e
-
- DIR="$(dirname "$0")"
- SHELLS="bash sh ash dash zsh ksh"
-
- echo "Legend:"
- echo " ∞=script does not halt (after 1 second timeout)"
- echo " X=disown unsupported by shell"
- echo " ☠=all children killed"
- echo " 🏃=all children still running"
- echo " ✔️=expected result (job killed, disowned child alive)"
- echo
-
- printf '\t'
- for shell in $SHELLS
- do
- if ! command -v "$shell" >/dev/null
- then
- >&2 echo "Shell $shell not found."
- exit 1
- fi
- printf '\t%s' "$shell"
- done
- printf '\n'
-
- for script in "$DIR"/../*.sh
- do
- if [ -x "$script" ] && grep -qF 'kill_child_jobs()' "$script" && ! grep -qF 'wait' "$script"
- then
- name="$(basename "$script")"
- printf '%s' "$name"
- if [ ${#name} -lt 8 ]
- then
- printf '\t'
- fi
-
- for shell in $SHELLS
- do
- printf '\t'
- "$DIR/test-kill-child-jobs.sh" "$script" "$shell" || true
- done
-
- printf '\n'
- fi
- done
|