Skip to content

Instantly share code, notes, and snippets.

@selbyk
Created March 17, 2016 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selbyk/cad68be266d8963cf415 to your computer and use it in GitHub Desktop.
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
#/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