Last active
January 15, 2018 11:12
-
-
Save zhouyl/bf381457800861518775a3760e3e43b0 to your computer and use it in GitHub Desktop.
/usr/local/bin/fkill
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 | |
PATTERN=$1 | |
if [ -z $PATTERN ] ; then | |
echo "Usage: fkill <GREP PATTERN>" | |
exit -1 | |
fi | |
CMD=$(/bin/ps -ef | grep -v grep | grep -v fkill | grep "$PATTERN") | |
CNT=$(/bin/ps -ef | grep -v grep | grep -v fkill | grep "$PATTERN" | wc -l) | |
if [[ $CNT -gt 0 ]] ; then | |
echo "Force killed processes listing:" | |
echo "---------------------------------------------------------------------" | |
echo "$CMD" | |
/bin/ps -ef | grep -v grep | grep -v fkill | grep "$PATTERN" | awk '{print $2}' | xargs kill -9 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment