Created
March 17, 2016 16:13
-
-
Save selbyk/cad68be266d8963cf415 to your computer and use it in GitHub Desktop.
accepts a command line argument for the process name, returns an exit code of 1 if the process is currently running
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/bash | |
# Usage: ./find_running_process.sh <process_name> | |
# DEBUG=1 ./find_running_process.sh <process_name> | |
# Function to help with debug messages | |
debug_message () { | |
if [ $DEBUG -eq 1 ] | |
then | |
echo $1 | |
fi | |
} | |
# Setup DEBUG var | |
if [ -z "$DEBUG" ]; then DEBUG=0; else DEBUG=1; fi | |
# Search for proc pid | |
PROC_PID=$(pgrep $1 || echo 0) | |
# Let user know whether or not debugging messages are enabled | |
debug_message "Debugging enabled" | |
# See if a pid was found | |
if [ $PROC_PID -eq 0 ] | |
then | |
debug_message "Not found: $1" | |
exit 0 | |
else | |
debug_message "Found running proc: $1:$PROC_PID" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment