CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
flock problems

 



rkota2
newbie

Jul 12, 2001, 1:49 PM

Post #1 of 1 (548 views)
flock problems Can't Post

#!/usr/misc/bin/perl -w

use Fcntl qw(:flock); # import LOCK_* constants

sub lock {
flock(MBOX,LOCK_EX);
# and, in case someone appended
# while we were waiting...
seek(MBOX, 0, 2);
}

sub unlock {
flock(MBOX,LOCK_UN);
}

open(MBOX, ">/usr/test/test.pl") or die "Can't open mailbox: $!";

lock();
$msg = "HELLO HOW ARE YOU!!!!!!";
print MBOX $msg,"\n\n";
unlock();


I tried the above piece of code, my code just hangs waiting for exclusive lock. I just created the file and I am pretty sure that there is no other program that accesses this file.

I tried shared lock and I opened the file in append mode and the code works just fine.

Any insights or resolution to this problem is greatly appreciated.

Kota


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives