gregor weertman
Programmer
I have this problem.
I want to be sure a script will not start twice.
The method I use now is:
pattr="sh.-c|vi|tail|view|grep|$$"
running=`ps -ef |grep ./program.sh |egrep -vic "$pattr"`
if [ "$running" -ne 0 ]
then
echo already running.
exit
fi
This is not watertight.
When the system has not enough recourses the script will start twice.
I can also use a lockfile.
I can write the pid in it
When the file exists, search for the pid, when not there start.
When the file not exists start
When running and file removed stop
Is there a better way?
How did unix solve this.
What system prevents me from starting cron twice.
Regards Gregor.
Gregor.Weertman@mailcity.com
I want to be sure a script will not start twice.
The method I use now is:
pattr="sh.-c|vi|tail|view|grep|$$"
running=`ps -ef |grep ./program.sh |egrep -vic "$pattr"`
if [ "$running" -ne 0 ]
then
echo already running.
exit
fi
This is not watertight.
When the system has not enough recourses the script will start twice.
I can also use a lockfile.
I can write the pid in it
When the file exists, search for the pid, when not there start.
When the file not exists start
When running and file removed stop
Is there a better way?
How did unix solve this.
What system prevents me from starting cron twice.
Regards Gregor.
Gregor.Weertman@mailcity.com