Created
June 20, 2012 00:36
-
-
Save unixpickle/2957418 to your computer and use it in GitHub Desktop.
Get the process ID for a process name
This file contains hidden or 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/bash | |
# | |
# Quickly get a PID for a given process name. | |
# | |
if [ $# -lt 1 ]; then | |
echo 'Usage: pidof <command name>' >&2 | |
exit 1 | |
fi | |
lines=`ps aux -c | grep "$1" | sed -e 's/^[^0-9]*\([0-9]*\).*/\1/g'` | |
if [ "$lines" = "" ]; then | |
echo "error: no process found: \`$1'" >&2 | |
exit 1 | |
fi | |
echo -n `echo ${lines} | head -n 1` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment