The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: process
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 02-07-2007
BOFH BOFH is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 406

Code:
#!/bin/ksh

PID=$$

if [[ -f /var/run/script.pid ]]
then
  OLDPID=`cat /var/run/script.pid`
  RUNNING=`ps -e | grep $OLDPID`
  if [[ ! -z "$RUNNING" ]]
  then
    exit 1
  fi
fi

echo $PID > /var/run/script.pid

# your code here

if [[ -f /var/run/script.pid ]]
then
  rm /var/run/script.pid
fi

Carl