Skip to content

Instantly share code, notes, and snippets.

@zeraf29
Created November 14, 2017 02:51
Show Gist options
  • Save zeraf29/6f0474d359d33331aa2b1db6abeab529 to your computer and use it in GitHub Desktop.
Save zeraf29/6f0474d359d33331aa2b1db6abeab529 to your computer and use it in GitHub Desktop.
Checking already running shell or not
#!/bin/bash
# JINHYUP KIM
cd /data/program/bin #move to directory
pid=`ps -ef | grep "Programname" | grep -v 'grep' | awk '{print $2}'`
#Get PID for checking already running or not
#ps -ef : Get information about running process. -e: Every proecss's , -f: Detail Information
# | grep "Programname" : Find process contained "Programname" pattern on "ps -ef" result.
# | grep -v 'grep': Get result of not included 'grep'. Can get process info except "grep" searching process.
# | awk '{print $2}' : Get information of second($2) value in "ps -ef | grep "Programname" | grep -v 'grep'". $2(second) value is PID.
if [ -z $pid ] # -z: checking string size is zero or not. size is zero = true. (If pid size zero, this prgram is not running now)
then #if not running yet, #JHK
#Put your main code what you want.
else #if already running, echo #JHK
echo "Already Running"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment