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?
tsniffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
I have seen various reports of the same problem which are related to Linux kernel bugs and NFS.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prakashagrCommented:

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
0
tsniffAuthor Commented:
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.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

TintinCommented:
My best guess is that the file lives on a NFS directory.
0
tsniffAuthor Commented:
I believe it does....  if so, is there a way to flock over nfs?
0
TintinCommented:
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.
0
ozoCommented:
Why not use a local file for a lock file?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.