in reply to RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)

I often use:
use Fcntl qw !LOCK_EX LOCK_NB!; die "Another instance is already running" unless flock DATA, LOCK_EX|LOCK_NB; ... your code here ... # Don't forget __END__ or __DATA__ __END__
Note that file locking solutions only prevent concurrent running on the same OS instance. If the job can be run from different machines, but you want to prevent concurrent runs from different boxes, you'll need a different solution. (Acquiring a database lock for instance).
  • Comment on Re: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
  • Download Code

Replies are listed 'Best First'.
Re^2: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
by Your Mother (Archbishop) on Dec 03, 2009 at 00:22 UTC

    That works? That's hot.

Re^2: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
by Anonymous Monk on Dec 04, 2009 at 19:42 UTC
Re^2: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
by mpeg4codec (Pilgrim) on Dec 03, 2009 at 00:48 UTC
    It's beautiful.