using centos5 below is my shell script. I want to prevent it from multiple instance.. but it doesn't work with if I fir "kill -9" option. also I doubt It will work on reboot. Is there anyway to apply this logic ? which can also handle kill -9 or reboot or any signal which cause manual exit of the script ?
[root@manage aaa]# cat script.sh
#!/bin/sh
set -e
scriptname=$(basename $0)
pidfile="/var/run/${scriptname}"
# lock it
exec 200>$pidfile
flock -n 200 || exit 1
pid=$$
echo $pid 1>&200
#### SCRIPT CODE