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 -->
  #3 (permalink)  
Old 02-07-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Use a temporary lockfile containing the process id, e.g...
Code:
#!/usr/bin/ksh

LOCKFILE=/tmp/lockfile

#---At the start of your script check to see that a lockfile exists
if [[ -f $LOCKFILE ]]
then
    #----If the lockfile does exist then check that the process is still running
    #     since it may have aborted and left the lockfile behind
    if ps -p $(<$LOCKFILE) >/dev/null
    then
        echo job is still running
        exit
    fi
fi

#---Must be okay to run, so create the lockfile containing the process id
echo $$ > $LOCKFILE

#----Rest of script goes here
:

#----end
rm $LOCKFILE
Not tested.