Created
October 5, 2025 13:58
-
-
Save erincerys/0e279e08c57e5c276bf8a3ded25b1a52 to your computer and use it in GitHub Desktop.
Issues progressively more severe kill signals to one or more PIDs
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
#!/bin/bash | |
test -z "$1" && exit 1 | |
declare -a _PGREP; _PGREP+=('pgrep') | |
test ${#1} > 15 && _PGREP+=('--full') | |
_PGREP+=('--ignore-ancestors' "$1") | |
mapfile -t _PIDS < <("${_PGREP[@]}") | |
test ${#_PIDS[@]} = 0 && exit 1 | |
_SIGNALS=(15 1 3 6 9) | |
for _SIGNAL in "${_SIGNALS[@]}"; do | |
test $_SIGNAL != 15 && \ | |
mapfile -t _PIDS < <("${_PGREP[@]}") | |
for _PID in "${_PIDS[@]}"; do | |
kill -$_SIGNAL $_PID >/dev/null 2>&1 | |
done | |
sleep 0.25 | |
mapfile -t _PIDS < <("${_PGREP[@]}") | |
test ${#_PIDS[@]} = 0 && break | |
sleep 4.75 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment