Bracing against the wind  
www.documentroot.com  

Sunday, December 05, 2010

Perl don't run this script more than once

I find myself writing this kind of code, preventing a script from being run more than once, in a lot of different ways - for no good reason. This method seems to work the best for me over the years:


use File::Pid;
my $pf = File::Pid->new;
exit(0) if $pf->running;
$pf->write();
END {$pf->remove();}

The IPC and mutex stuff is cute, but not portable... or transparent. Plus, it's nice to have a pidfile out there for other reasons.

(When I forget how I solved a problem, I post it here. That way, I can google and get an answer.)

[View/Post Comments] [Digg] [Del.icio.us] [Stumble]

Home | Email me when this weblog updates: | View Archive

(C) 2002 Erik Aronesty/DocumentRoot.Com. Right to copy, without attribution, is given freely to anyone for any reason.


Listed on BlogShares | Bloghop: the best pretty good | Blogarama | Technorati | Blogwise