Operating System - Tru64 Unix
1753670 Members
5152 Online
108799 Solutions
New Discussion юеВ

Perl / flock oddity

 
SOLVED
Go to solution
Mark Poeschl_2
Honored Contributor

Perl / flock oddity

I don't know if this is a "feature" of perl, or just an oddity of perl on Tru64 but I thought I'd post here and see if it rings any bells with anyone.

Tru64 5.1B / Patch Kit 4

I'm trying to use the 'flock' system call from within a perl script. The code is attached. It turns out that if I don't explicity reset the OS_ERROR variable '$!' in the program, it never detects that the lock has been released. I.E. with the line commented out as in the attachment, the second and all subsequent invocations of the program just wait in the 15 second loop indefinitely. If you uncomment the line '$! = 0;' it works just fine.

Does this make sense to anybody? What am I missing?

TIA...
6 REPLIES 6
Sreedhar_12
New Member

Re: Perl / flock oddity

Hello,

I tried executing the attached program. It works as expected (even with commenting the statement " $! == 0; ". I tested on system with V5.1B + patchkit4. Can you let us knwo the version of the perl you are using "perl -v". Logs are attached.

/Sreedhar
Mark Poeschl_2
Honored Contributor

Re: Perl / flock oddity

Thanks Sreedhar - I'm on perl 5.8.0 as well. Your logs show only one invocation of the program. Are you seeing expected behavior with multiple invocations as well? I only have a problem with multiple simultaneous runs of the program.
Michael Schulte zur Sur
Honored Contributor

Re: Perl / flock oddity

Mark,

as my perl book says, $! is only set in case of an os system error. You probably have to reset it yourself.

greetings,

Michael
Sreedhar_12
New Member

Re: Perl / flock oddity

Hi Mark,

I am able to reproduce the reported problem with multiple invocations. I tested in other flavours of UNIX (Solaris and HP-UX). Logs are attached. There perl is behaving differently. No difference is seen in behaviour with/with out commenting out the statement "$! == 0".

/Sreedhar
Michael Schulte zur Sur
Honored Contributor
Solution

Re: Perl / flock oddity

Hi,

the code should work as follows.
Got that with the help of procura.

greetings,

Michael


if (flock (HANDLE, (LOCK_EX|LOCK_NB)))
{
print STDOUT "Lock acquired - sleeping for one minute\n" ;
$waiting = 0;
sleep 60 ;
} else
{
if ( $! == EWOULDBLOCK )
{
...
Mark Poeschl_2
Honored Contributor

Re: Perl / flock oddity

Perfect - thanks Michael.