bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:
So, here is the flow that I want.#!/usr/bin/perl use strict; use Fcntl qw( :flock ); use Getopt::Long; GetOptions( 'test' => \my $option_test ); print "Running $0\n"; check_process() if ( ! defined( $option_test ) ); sleep 30; print "Running $0\n"; sub check_process { open( SELF, '<', $0 ) || die "Error: Cannot open $0 for locking - $!\n"; flock( SELF, LOCK_EX | LOCK_NB ) || die "Error: Another $0 is already running.\n"; return 1; }
So, I am thinking of just creating a new script for (test.pl --test), but the reason why I am hesitant to this is because the new script is almost 95% identical to the main script.$ perl test.pl --> should run if there is no test.pl running. $ perl test.pl ---> should abort if there is a test.pl running alread +y. $ perl test.pl --test --> should run even if test.pl is already runni +ng. $ perl test.pl --test --> should abort if there is a (test.pl --test) + running as well.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Conditional Lock File
by roboticus (Chancellor) on Feb 02, 2011 at 19:53 UTC | |
by bichonfrise74 (Vicar) on Feb 02, 2011 at 20:35 UTC |