On Wed, 30 Jul 2003 02:14:45 +0500, [EMAIL PROTECTED] (Sara) wrote:

>What could be the simplest test to check 'flock' working on your server or not?
>
>except for writing to support team of host ::))
>
>Thanks for any input.
Start the following script in 2 different terminals or xterms
simultaneously. The first one should hold the lock for 10 seconds,
then the second instance should take over. (If flock works).

#!/usr/bin/perl
use Fcntl ':flock'; # import LOCK_* constants
$|=1;

#run this twice and the second run will not run until first finishes

sub get_lock{
  open(SEM, ">$semaphore_file") || die "Cannot create semaphore: $!";
  flock(SEM, LOCK_EX) || die "Lock failed: $!";
}

sub release_lock{ close(SEM);}

$semaphore_file="flock-sub-semfile";
get_lock();

for(1..10){ 
     print "got lock";
     sleep 1;
}
#Do something here

release_lock;
__END__



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to