G
Guy
I can't flock, it returns 0, any ideas.
This was suppose to be a small test script that would lock a file, the loop
for a certain amount of time, and then close the file.
I wanted to run this script to see if it would affect my other perl script
whi is trying to access the same file.
From what I read, I'm assuming that when you close a file, it also unlocks
it, so I'm guessing that you don't really have to unlock it before closing
it.
Just so you know '$l' is lower case $L. I guess i should choose more legible
scalars. The font here is pretty bad!
Anyway, my HTML page submits the variables f and l.
Variable f is just a delay variable, value of 50 give me like a 10 to 15
second delay. (so I thought the file would be locked for 10 to 15 seconds)
Variable l contains the operation I want to use on flock.
I tried 1,2, and 8, but it doesn't appear to lock the file, and the flock
function returns 0.
I'm not sure about 4 (NB), I think you have to add it to the 1, 2, or 8.
So I even tried with 5, and 6 but it still returns 0.
At first, this was actually hard coded, my command actually read $chk=flock
LCKFILE,2;
When I telnet to the server and do ls -l, it shows that the file has
_rw_rw_rw_
Is there anything I am missing.
This is my first attempt at using flock.
Guy Doucet
#!/usr/local/bin/perl -w
use CGI qwstandard);
no warnings;
print header();
$fd="../data";
$lockfil="$fd/lock.txt";
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);$CONFILTERED=~tr/+/
/;$CONFILTERED=~s/%(..)/pack("c",hex($1))/ge;
if($key eq "f"){$f=$content;}
if($key eq "l"){$l=$content;}
}
print"<HTML><BODY>\n";
$gchk=locksys(); # Lock file access
if($gchk==0){while($f>0){$f--;$t=64000;while($t>0){$t--;$a = 1234;$b = 31;$c
= $a * $b / 3;}}&unlocksys;}
print"Done!<BR></BODY></HTML>\n";
sub locksys{
my $chk=3840;
if(-d "$fd"){$chk=3584;if(open(LCKFILE,"$lockfil")){$chk=flock
LCKFILE,$l;}}
print"chk=:$chk:<BR>\n";
return $chk;
}
sub unlocksys{
close LCKFILE;
}
This was suppose to be a small test script that would lock a file, the loop
for a certain amount of time, and then close the file.
I wanted to run this script to see if it would affect my other perl script
whi is trying to access the same file.
From what I read, I'm assuming that when you close a file, it also unlocks
it, so I'm guessing that you don't really have to unlock it before closing
it.
Just so you know '$l' is lower case $L. I guess i should choose more legible
scalars. The font here is pretty bad!
Anyway, my HTML page submits the variables f and l.
Variable f is just a delay variable, value of 50 give me like a 10 to 15
second delay. (so I thought the file would be locked for 10 to 15 seconds)
Variable l contains the operation I want to use on flock.
I tried 1,2, and 8, but it doesn't appear to lock the file, and the flock
function returns 0.
I'm not sure about 4 (NB), I think you have to add it to the 1, 2, or 8.
So I even tried with 5, and 6 but it still returns 0.
At first, this was actually hard coded, my command actually read $chk=flock
LCKFILE,2;
When I telnet to the server and do ls -l, it shows that the file has
_rw_rw_rw_
Is there anything I am missing.
This is my first attempt at using flock.
Guy Doucet
#!/usr/local/bin/perl -w
use CGI qwstandard);
no warnings;
print header();
$fd="../data";
$lockfil="$fd/lock.txt";
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);$CONFILTERED=~tr/+/
/;$CONFILTERED=~s/%(..)/pack("c",hex($1))/ge;
if($key eq "f"){$f=$content;}
if($key eq "l"){$l=$content;}
}
print"<HTML><BODY>\n";
$gchk=locksys(); # Lock file access
if($gchk==0){while($f>0){$f--;$t=64000;while($t>0){$t--;$a = 1234;$b = 31;$c
= $a * $b / 3;}}&unlocksys;}
print"Done!<BR></BODY></HTML>\n";
sub locksys{
my $chk=3840;
if(-d "$fd"){$chk=3584;if(open(LCKFILE,"$lockfil")){$chk=flock
LCKFILE,$l;}}
print"chk=:$chk:<BR>\n";
return $chk;
}
sub unlocksys{
close LCKFILE;
}