use Fcntl qw(:flock);
until(flock $fh, LOCK_EX|LOCK_NB)
{
$lockwait++;
if($lockwait == 10)
{
print STDERR "timed out waiting for lock\n";
exit 1;
}
sleep 1;
}
this will do a non-blocking attempt to get the lock, and try 10 times to
get it.
On Wed, 31 Oct 2001 [EMAIL PROTECTED] wrote:
> Hi,
>
> I'm trying to lock a file exclusively so that other process has no access
> to it
> I'm using:
>
> flock($fh,2);
>
> It does work, and in the second process I use the same procedure.
>
> The problem is that I can't set a time limit for the lock.
> I want to try to capture the lock, and if unsuccessful, the process should
> give up and exit.
>
> It just so happens that the second process waits and waits until the first
> process finishes.
>
> Any idea as to how to impose a time limit on the lock ?
>
> I have tried the following and other loops but it just freezes execution at
> flock
>
> unless (flock($fh,2)) {
> exit;
> }
>
> # lock ok
>
>
> Any help is welcome
> Thanks
> Edgar.
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]