[rochester-pm-list] flock question

Justin C. Sherrill webmaster at rochester.rr.com
Thu Jun 17 09:14:15 CDT 1999


Here's something I never understood about flock(), and I haven't really had
the chance to test it out.  Could someone on this list hazard an answer for
me?  For instance, I have this chunk of code:

open (DB_FH, ">&=$fd") or print "Cant open $fd : $!\n";
# I have no clue what +<&= does.  It's in the Cookbook.
flock (BD_FH, LOCK_EX);
# do stuff to file here that I took out for space
$db->sync;
flock(DB_FH, LOCK_UN);
close (DB_FH);

What I'm not sure about is this: I can get an exclusive lock here, which is
fine.  However, this script is running as part of a CGI I wrote, and so
multiple instances may run at the same time depending on traffic.  Do I have
to do some sort of check for an existing exclusive lock before obtaining
one, or will a new lock coming from another process with this script
automatically wait until the first process releases the lock?

Justin C. Sherrill
Rochester Road Runner Webmaster
http://www.rochester.rr.com/
"Think slow, type fats"




More information about the Rochester-pm mailing list