Last active
October 12, 2020 23:25
-
-
Save ilyaevseev/902b7c2de6b480cff6c8741cb7ab26d4 to your computer and use it in GitHub Desktop.
Kill process tree - shell function and script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
KILLSIG="" | |
walktree() { local p=""; for p in "$@"; do walktree $(pgrep -P "$p"); echo $p; done; } | |
test "${1#-}" != "$1" && KILLSIG="$1" && shift | |
test $# = "0" && echo "Usage: ${0##*/} pid ..." && exit | |
PIDS="$(walktree "$@")" | |
while kill $KILLSIG $PIDS; do sleep 0.2; done | |
exit 0 | |
## END ## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
killtree() { | |
local KILLSIG="" | |
test "${1#-}" = "$1" || { KILLSIG="$1"; shift; } | |
test $# = "0" && echo "Usage: ${0##*/} pid ..." && return 1 | |
local p=""; for p in "$@"; do killtree $(pgrep -P "$p"); kill $KILLSIG "$p"; done; | |
} | |
killtree "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment