[CentOS] Re: Any one have a good example...

Tue Aug 29 19:44:56 UTC 2006
Scott Silva <ssilva at sgvwater.com>

James Olin Oden spake the following on 8/29/2006 12:42 PM:
> On 8/29/06, mike.redan at bell.ca
> <mike.redan at bell.ca> wrote:
>> Something like this works alright:
>>
>>
>> # Check if process is running already
>> SCRIPT_NAME=do_stuff
>> pidfile=/tmp/$SCRIPT_NAME.pid
>>
>>
>> if [ -f $pidfile ]; then
>>   runpid=`cat $pidfile`
>>   if ps -p $runpid; then
>>      echo "$SCRIPT_NAME is already running ... stopping"
>>      exit 1
>>   else
>>      echo "$SCRIPT_NAME pid found but process dead, cleaning up and
>> starting ..."
>>      rm -f $pidfile
>>   fi
>> else
>>   echo "No $SCRIPT_NAME Process Detected ... starting"
>> fi
>>
>> echo $$ > $pidfile
>>
> As long as you don't have multiple scripts starting at approximately
> the same time.   I use this same algorithm sometimes but I always use
> flock() because otherwise there is a race condition.  Even using
> flock() does not remove the race on the creation of the file, though,
> which is why if you really want to remove the race condition you make
> sure the file pre-existant (via package delivery or something to that
> affect).
> 
> At least this is how I understand the problem....james
Basically it is for an rsync script that runs once an hour, but occasionally,
the process takes more than an hour, and another one starts. I also thought of
using the --timeout parameter for rsync, but wanted to do a little option
checking.


-- 

MailScanner is like deodorant...
You hope everybody uses it, and
you notice quickly if they don't!!!!