Skip to content

Instantly share code, notes, and snippets.

@sobi3ch
Created September 9, 2013 12:25
Show Gist options
  • Save sobi3ch/6494891 to your computer and use it in GitHub Desktop.
Save sobi3ch/6494891 to your computer and use it in GitHub Desktop.
Test if a given process is running. Assuming this form process list (ps).
#!/bin/bash
# Save process name to search
PROCESS=$1
# Change 'myapp' > '[m]yapp so grep don't count itself
GREP_PROCESS=`echo $PROCESS | sed 's/^\(.\)/[\1]/'`
# List processes, remove self command name and on the end count wanted process
COUNT=$(ps ax | grep -v $0 | grep -c -i $GREP_PROCESS)
if [ $COUNT -gt 0 ]
then
echo Running;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment