Created
April 1, 2025 01:00
-
-
Save ytxmobile98/572200c9eb18f4583e2c3d7cf3dbbe05 to your computer and use it in GitHub Desktop.
Kill a PID and all its descendants
This file contains hidden or 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 | |
| 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