Click to See Complete Forum and Search --> : Perl -> Fcntl ':flock' help?


goofball
07-25-2003, 12:37 PM
I'm using flock in a Perl script when overwriting a database file. It works fine, and evidently prevents another process from overwriting the same file at the same time (as long as this other script is also using flock), but I need to know if it also prevents read access.

The database is composed of .pl files that are required by the database scripts all the time, so I want to know if using flock on a file would prevent that file from being read or required from another process. ??

Part of the script is below so you can see what I'm doing:


use Fcntl ':flock';
sub lock {
flock($_[0],LOCK_EX);
seek($_[0], 0, 2);
}

open(FILEHANDLE, ">../log_file.pl");
&lock('FILEHANDLE');

print FILEHANDLE "blah blah blah\n";

flock(FILEHANDLE,LOCK_UN);
close(FILEHANDLE);


Thanks!

Jeff Mott
07-28-2003, 12:37 PM
I couldn't find any official documentation to say definitively one way or the other, but testing on my system shows that a file being locked _will_ prevent it from being required. And, the require does not wait for the lock to be released. It will simply return an error.

goofball
07-28-2003, 02:54 PM
Bummer.
But thanks for your input!

Maybe I'll have to try using Perl DBM in stead ...