[Omaha.pm] Quick Bail
Kenneth Thompson
kthompson at omnihotels.com
Thu Sep 1 15:22:35 PDT 2005
A short one-liner to keep a script from executing more than one at a
time (say a long running script kicked off from cron every minute that
runs more than a minute occasionally...
my @ps = `ps -ef | grep $0 | grep -v grep`; exit if ( @ps > 1);
and a more advanced version...
my @procs = grep /perl .*invan\.pl/, `ps axw`;
if (@procs > 1) {
unless ($ENV{USER} eq "jhannah") { # Hopefully that dork knows what
he's doing, so let him do whatever.
die "Looks like I'm already running. I refuse to run on top of
myself.\n @procs";
}
}
Kenn Thompson
Omni Hotels Reservation Center
Sr. Programmer/Analyst
w:402.952.6521
c:402.598.8818
Omni Hotels is proud to be ranked "Highest in Guest Satisfaction Among
Upscale Hotel Chains" in the J.D. Power and Associates 2005 North
America Hotel Guest Satisfaction StudySM.
(Study based on 37,471 responses from guests who stayed in a hotel
between December 2004 and May 2005. Fourteen upscale hotel chains were
ranked in the study. www.jdpower.com <http://www.jdpower.com> )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20050901/2aac4f35/attachment.html
More information about the Omaha-pm
mailing list