-
-
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
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 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