Re: Cannot lock a file.
From: Alex939393929 (aprutgers_at_hotmail.com)
Date: 03/24/04
- Next message: Alex939393929: "Re: Recommend IDE"
- Previous message: Roel van der Steen: "Re: Help - Counting text - Associative Array? (van_der_Steen)"
- In reply to: Hon Seng Phuah: "Cannot lock a file."
- Next in thread: Hon Seng Phuah: "Re: Cannot lock a file."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Mar 2004 13:38:12 -0800
hsphuah@usa.com (Hon Seng Phuah) wrote in message news:<3898598f.0403240014.4614c926@posting.google.com>...
> Hi all,
>
> I have following code:
>
> use 5.004'
> use Fcntl ':flock';
>
> sub check_file_status
> {
> $attempt_lock = 0;
> $max_attempts = 3;
> open(in_file, "$check_in_file_name");
> while (!flock(in_file, LOCK_EX) && $attemp_lock < $max_attempts)
> {
> sleep(5);
>
> }
> close(in_file);
> }
>
> I cannot get the exlusive lock for the $check_in_file_name variable
> file name. Any idea? How should I correct my mistake?
tried it with perl 5.6.0, no problemo, note flock does not
work for network files (e.g. files retrieved via nfs mount point).
see perldoc -f flock
use 5.004;
use Fcntl ':flock';
sub check_file_status
{
$attempt_lock = 0;
$max_attempts = 3;
my $check_in_file_name = 'file1.txt';
open(in_file, "<$check_in_file_name")||print "$check_in_file_name:$!\n";
while (!flock(in_file, LOCK_EX) && $attemp_lock < $max_attempts)
{
print "lock attempt $!\n";
sleep(5);
$attemp_lock++;
}
close(in_file);
}
check_file_status();
- Next message: Alex939393929: "Re: Recommend IDE"
- Previous message: Roel van der Steen: "Re: Help - Counting text - Associative Array? (van_der_Steen)"
- In reply to: Hon Seng Phuah: "Cannot lock a file."
- Next in thread: Hon Seng Phuah: "Re: Cannot lock a file."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|