S
sonet
when i use flock to lock file, i can not read the file from another program.
how to lock a file avoid append operate but can read it in the same time.
open(HANDLE,">>flockfile");
&lock;
for (1..5){
print HANDLE "process $$ is adding this line # $_\n";
sleep 2;
}
close(HANDLE);
sub lock {
print "Now trying to get lock...\n";
flock(HANDLE,2) or die "could not lock file: $!"; # exclusive lock
with "2"
print "locked!\n";
seek(HANDLE, 0, 2);
}
how to lock a file avoid append operate but can read it in the same time.
open(HANDLE,">>flockfile");
&lock;
for (1..5){
print HANDLE "process $$ is adding this line # $_\n";
sleep 2;
}
close(HANDLE);
sub lock {
print "Now trying to get lock...\n";
flock(HANDLE,2) or die "could not lock file: $!"; # exclusive lock
with "2"
print "locked!\n";
seek(HANDLE, 0, 2);
}