I'm not talking about lockfiles. I'm talking about using the file locking mechanisms that are built into your operating system. If you get an exclusive lock on a file, then any other process trying to get an exclusive lock on the same file will block until the first lock is released.
| [reply] |
The locking mechanism seems to require a file that can be locked My first attempt resulted in a permission denied :)
But I'm looking for something like
#! /usr/bin/perl -lw
use strict;
use Shell qw(ps);
my $sh = Shell->new;
my @pids = grep ( $_ =~ /t\.pl/, $sh->ps('aux'));
print "list of running instances:\n@pids\n" ;
for( @pids ) {
exit if ( $_ && /t\.pl\s.*\-a/ ) ;
}
print "no other instance running\n" ;
Which actually seems to work quite good :)
LuCa | [reply] [d/l] |
The locking mechanism seems to require a file that can be locked
My first attempt resulted in a permission denied :)
Hmm, can we dig into that little problem, please?
Many systems only allow you to lock a file (actually a file handle) that you have open for writing. Once that condition is met, it really ought to work.
Oh, and if you try to lock the file in nonblocking mode, it won't wait but instead report failure to lock. Store that result and you will know whether to output anything, or not.
BTW I'd prefer to always enable warnings, but let every instance have their own copy for the log file.
| [reply] |
The locking mechanism seems to require a file that can be locked
Yes. You lock the file that you're going to write to.
But we're obviously talking at complete cross-purposes here, so I'm going to withdraw from this discussion and let someone else help you.
| [reply] |
| [reply] |