develooper Front page | perl.beginners | Postings from October 2007

Re: Limiting a program to a single running instance

Thread Previous | Thread Next
From:
Ken Foskey
Date:
October 3, 2007 15:50
Subject:
Re: Limiting a program to a single running instance
Message ID:
1191451849.20887.18.camel@froddo.foskey.org.au

On Wed, 2007-10-03 at 13:34 -0700, Mark Wagner 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.

http://search.cpan.org/~elizabeth/Sys-RunAlone-0.07/lib/Sys/RunAlone.pm

Another design for this sort of thing is a mutex.  There are a few
modules for this.  This means you can lock out smaller parts of code and
keep two copies running concurrently doing different work.

-- 
Ken Foskey
FOSS developer


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About