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.

47 lines
1002 B

  1. #!/bin/sh
  2. set -e
  3. DIR="$(dirname "$0")"
  4. SHELLS="bash sh ash dash zsh ksh"
  5. echo "Legend:"
  6. echo " ∞=script does not halt (after 1 second timeout)"
  7. echo " X=disown unsupported by shell"
  8. echo " ☠=all children killed"
  9. echo " 🏃=all children still running"
  10. echo " ✔️=expected result (job killed, disowned child alive)"
  11. echo
  12. printf '\t'
  13. for shell in $SHELLS
  14. do
  15. if ! command -v "$shell" >/dev/null
  16. then
  17. >&2 echo "Shell $shell not found."
  18. exit 1
  19. fi
  20. printf '\t%s' "$shell"
  21. done
  22. printf '\n'
  23. for script in "$DIR"/../*.sh
  24. do
  25. if [ -x "$script" ] && grep -qF 'kill_child_jobs()' "$script" && ! grep -qF 'wait' "$script"
  26. then
  27. name="$(basename "$script")"
  28. printf '%s' "$name"
  29. if [ ${#name} -lt 8 ]
  30. then
  31. printf '\t'
  32. fi
  33. for shell in $SHELLS
  34. do
  35. printf '\t'
  36. "$DIR/test-kill-child-jobs.sh" "$script" "$shell" || true
  37. done
  38. printf '\n'
  39. fi
  40. done