Skip to content

Instantly share code, notes, and snippets.

@zhouyl
Last active January 15, 2018 11:12
Show Gist options
  • Save zhouyl/bf381457800861518775a3760e3e43b0 to your computer and use it in GitHub Desktop.
Save zhouyl/bf381457800861518775a3760e3e43b0 to your computer and use it in GitHub Desktop.
/usr/local/bin/fkill
#!/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