Skip to content

Instantly share code, notes, and snippets.

@amishurov
Last active May 16, 2016 13:13
Show Gist options
  • Save amishurov/c7473d7d75f8ba29fdc18b17b0d3bf9a to your computer and use it in GitHub Desktop.
Save amishurov/c7473d7d75f8ba29fdc18b17b0d3bf9a to your computer and use it in GitHub Desktop.
recusive kill children for PID
#!/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