1
0

Compare commits

...

3 Commits

3 changed files with 20 additions and 22 deletions

View File

@ -35,11 +35,8 @@ cleanup() {
kill_child_jobs kill_child_jobs
} }
#trap "kill_child_jobs" INT TERM QUIT
#trap date INT TERM QUIT
# From https://unix.stackexchange.com/a/240736 # From https://unix.stackexchange.com/a/240736
for sig in INT QUIT HUP TERM ALRM USR1; do for sig in INT QUIT HUP TERM; do
trap " trap "
cleanup cleanup
trap - $sig EXIT trap - $sig EXIT

19
dash.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
set -e
# From https://stackoverflow.com/a/360275
kill_child_jobs() {
echo "In kill_child_jobs()..."
# Workaround for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482999
tmp="$(mktemp)"
jobs -p > "$tmp"
child_pids=$(cat "$tmp")
for child in $child_pids
do
echo Killing "$child"
# From https://stackoverflow.com/a/11231970
kill "$child" || true
done
rm "$tmp"
}

18
zsh.sh
View File

@ -8,21 +8,3 @@ kill_child_jobs() {
# From https://unix.stackexchange.com/a/544167 # From https://unix.stackexchange.com/a/544167
while kill %% >/dev/null; do :; done while kill %% >/dev/null; do :; done
} }
cleanup() {
kill_child_jobs
}
# From https://unix.stackexchange.com/a/240736
for sig in INT QUIT HUP TERM ALRM USR1; do
trap "
cleanup
trap - $sig EXIT
kill -s $sig "'"$$"' "$sig"
done
trap cleanup EXIT
yes aa &
yes b &
sleep 100 &
wait