-
-
Save Leask/6028569 to your computer and use it in GitHub Desktop.
Kill process by command (NOT ONLY by executable file name or pid, smarter than `killall`) Sample: $ sk /usr/sbin/securityd -i
This file contains 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/sh | |
# Flora Smart Kill by LeaskH.com | |
# Main logic | |
aPs="`ps -ef | grep "$*" | grep -v "grep $*" | grep -v "$0 $*"`" | |
pid="`echo "$aPs" | grep -v "sk" | head -1 | awk '{print $2}'`" | |
if [ "$pid" ]; then | |
kill $pid # 2> /dev/null | |
echo $pid | |
exit 0 | |
fi | |
echo 0 | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment