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