Skip to content

Instantly share code, notes, and snippets.

@Leask
Last active December 19, 2015 22:38
Show Gist options
  • Save Leask/6028569 to your computer and use it in GitHub Desktop.
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
#!/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