Last active
May 16, 2016 13:13
-
-
Save amishurov/c7473d7d75f8ba29fdc18b17b0d3bf9a to your computer and use it in GitHub Desktop.
recusive kill children for PID
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
#!/usr/bin/env bash | |
# Kills all children for passed PID recursively | |
function recursive_kill { | |
children=`pgrep -P $1` | |
if [ -z "$children" ]; then | |
kill -9 $1 && echo 'finish $1' | |
else | |
for child in $children; do | |
echo "killing `ps -p $child -o pid= -o cmd=`" | |
recursive_kill $child | |
done | |
fi | |
} | |
recursive_kill $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment