Skip to content

Instantly share code, notes, and snippets.

@Leask
Last active December 19, 2015 22:38
Show Gist options
  • Save Leask/6028443 to your computer and use it in GitHub Desktop.
Save Leask/6028443 to your computer and use it in GitHub Desktop.
Get pid by command (NOT ONLY by executable file name, different from `pidof` project) Sample: $ pid /usr/sbin/securityd -i
#!/bin/sh
# Flora Pid by LeaskH.com
# Main logic
aPs="`ps -ef | grep "$*" | grep -v "grep $*" | grep -v "$0 $*"`"
pid="`echo "$aPs" | grep -v "pid" | head -1 | awk '{print $2}'`"
if [ "$pid" ]; then
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