tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ simultaneous dbmopen

Question about using "system" command ▻

fcntl to lock a file?

In article <ri3ev9jppa.fsf@viman.com>, Matt Cline  <gandalf@viman.com> wrote:
>I'm trying to use fctnl to lock a file.  However, I keep on getting
>a "Bad file number" error, no matter what file number I give it.

Probably, you're trying to apply an exclusive lock through a file
descriptor open only for reading, or a shared lock through a file
descriptor open only for writing.  Neither of these makes sense,
so the system won't let you do it.

Shared locks can only be applied through filehandles open for reading,
and exclusive locks can only be applied through filehandles opened for
writing.

>Does someone have some existing code using fcntl that works?

I'd recommend using the File::Lock module.

Tim.
--
Tim Goodwin   | "A language needs both intestines and guts." -- Larry Wall

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: fcntl to lock a file?
Date: 7 Feb 1997 13:12:12 GMT
Organization: UUNET PIPEX
Message-ID: <5df9nc$fsh@join.news.pipex.net>
References: <ri3ev9jppa.fsf@viman.com>

△ comp.lang.perl △

◅ simultaneous dbmopen

Question about using "system" command ▻