Link to home
Start Free TrialLog in
Avatar of tsniff
tsniffFlag for United States of America

asked on

flock error - no locks available.

Here is a simple test script that creates the error.

use Fcntl qw(:DEFAULT :flock);
my $file = "test.txt";
print "Content-type:text/html\n\n";
local *FILE;
sysopen(FILE, $file, O_WRONLY | O_TRUNC | O_CREAT) or print "<p>Can't open $file: $!</p>";
flock(FILE, LOCK_EX) or print "<p>Can't flock LOCK_EX $file: $!</p>";
print FILE "Test\n";
flock(FILE, LOCK_UN) or print "<p>Can't flock LOCK_UN $file: $!</p>";
close(FILE);
print "<p>Done</p>";


It always produces the error:

Can't flock LOCK_EX test.txt: No locks available


I've never seen this before.  Anyone know why and how to fix it?
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

use Fcntl qw(:DEFAULT :flock);
my $file = "test.txt";
print "Content-type:text/html\n\n";
local *FILE;
sysopen(FILE, $file, O_WRONLY | O_TRUNC | O_CREAT) or print "<p>Can't open $file
: $!</p>";
flock(FILE, LOCK_EX) or print "<p>Can't flock LOCK_EX $file: $!</p>";
print FILE "Test\n";
flock(FILE, LOCK_UN) or print "<p>Can't flock LOCK_UN $file: $!</p>";
close(FILE);
print "<p>Done</p>";

~
[prakasha@linuxcvs prakasha]$ perl flock.pl
Content-type:text/html

<p>Done</p>[prakasha@linuxcvs prakasha]$


i am not getting that message, file is proper for me.

Prakash
Avatar of tsniff

ASKER

I know the file is fine.  It works on every server I have tested it on except one.  I am trying to find a reason and solution for that one.
Avatar of Tintin
Tintin

My best guess is that the file lives on a NFS directory.
Avatar of tsniff

ASKER

I believe it does....  if so, is there a way to flock over nfs?
As previously mentioned, I have seen reports of Linux kernel bugs preventing flock over NFS, so in order to fix this, your server would probably need a kernel upgrade.

As a workaround, you could use another file locking method.
Why not use a local file for a lock file?