Checking for instances by grepping the output of ps tends to also catch 
instances of 

vi myscript.pl

So that innocently editing the file on that box keeps it from running! Not what 
you have in mind, I think.

I suggest (untested, but we do something like this in the office):
Upon startup, check for the existence of a lockfile with agreed-upon name in 
some tmp directory.  If it exists, exit immediately; otherwise create the file. 
 Remove the file at end of execution or upon death of script (in the END block).

I haven't thought out all the ways that could go wrong. Comments welcome.


Cheers,

Liz 

 
On Wednesday, October 03, 2007, at 01:42PM, "Chas. Owens" <[EMAIL PROTECTED]> 
wrote:
>On 10/3/07, Mark Wagner <[EMAIL PROTECTED]> wrote:
>> I've got a Perl program that is run once an hour as a cron job.
>> Normally it finishes its task in about ten minutes, but occasionally
>> it takes more than an hour to complete.  When this happens, a second
>> copy is started, the two copies step on each others' toes, and both
>> crash.
>>
>> I'm looking for the second copy to know that another copy is running
>> and exit after logging a message to that effect.  Any method needs to
>> work properly if the first copy crashes rather than exiting cleanly.
>snip
>
>Create a gatekeeper script* that runs the script in question.  This
>gatekeeper script should look at the currently running processes
>(either using ps or some module suitable for your environment) and if
>the script is currently running don't execute the script.
>
>* or just add the functionality to your existing script, the benefit
>of having a general gatekeeper script is that if you need to do this
>again you can just pass different arguments in.
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>http://learn.perl.org/
>
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to