Created
November 29, 2016 21:18
-
-
Save mfdj/71d467fdadf83e04e2fb46f0a1941e28 to your computer and use it in GitHub Desktop.
Live dangerously: fuzzy match active processes by their name and tell them to go nigh'nigh
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
# shellcheck disable=SC2148 | |
shush() { | |
local procName matches match binary pid | |
for procName in "$@"; do | |
matches=$(ps aux | grep -i "$procName" | grep -v grep | sed -E 's/[[:space:]]+/ /g') | |
if [[ $matches ]]; then | |
echo "shushing processes that match '$procName'" | |
( | |
# line-by-line instead of word-by-word | |
IFS=$'\n' | |
for match in $matches; do | |
pid=$(echo "$match" | awk '{print $2}') | |
binary=$(echo "$match" | cut -d ' ' -f 11-) | |
# gaurd against over-shushing processes that quieted down when | |
# one of their peers got shushed | |
if ps aux | awk '{print $2}' | grep "$pid" > /dev/null; then | |
echo " pid '$pid' command '${binary:0:128}'" | |
kill -9 "$pid" | |
fi | |
done | |
) | |
else | |
echo "'$procName' already quiet!" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment