Skip to content

Instantly share code, notes, and snippets.

@ytxmobile98
Created April 1, 2025 01:00
Show Gist options
  • Select an option

  • Save ytxmobile98/572200c9eb18f4583e2c3d7cf3dbbe05 to your computer and use it in GitHub Desktop.

Select an option

Save ytxmobile98/572200c9eb18f4583e2c3d7cf3dbbe05 to your computer and use it in GitHub Desktop.
Kill a PID and all its descendants
#!/usr/bin/env bash
function kill_tree {
local pid=$1
local children=$(pgrep -P $pid)
for child in $children; do
kill_tree $child
done
kill -15 $pid
}
for pid in $@; do
kill_tree $pid
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment