Improved full example and added pkill-P version.

master
Daniel Perelman 3 years ago
parent 3b740f2e4d
commit 9c7b084555
  1. 3
      all-full-example.sh
  2. 28
      pkill-P-full-example.sh

@ -1,7 +1,6 @@
#!/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
@ -45,7 +44,7 @@ done
trap cleanup EXIT
yes aa &
yes b &
yes disowned & builtin disown || true
sleep 100 &
wait

@ -0,0 +1,28 @@
#!/bin/sh
set -e
kill_child_jobs() {
echo "In kill_child_jobs()..."
# From https://stackoverflow.com/a/23336595
# Kills all child proceses, not just jobs.
pkill -P $$
}
cleanup() {
kill_child_jobs
}
# From https://unix.stackexchange.com/a/240736
for sig in INT QUIT HUP TERM; do
trap "
cleanup
trap - $sig EXIT
kill -s $sig "'"$$"' "$sig"
done
trap cleanup EXIT
yes aa &
yes disowned & builtin disown || true
sleep 100 &
wait
Loading…
Cancel
Save