Re: file-locking and postmaster.pid - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: file-locking and postmaster.pid
Date
Msg-id 20060524203654.GB6607@surnet.cl
Whole thread Raw
In response to Re: file-locking and postmaster.pid  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: file-locking and postmaster.pid
List pgsql-hackers
Andrew Dunstan wrote:

> We use file locking on Win32 (and on all other platforms)  in the 
> buildfarm ... it's done from perl so maybe perl does some magic under 
> the hood. The call looks just the same, and works fine on W32, I 
> believe. It is roughly:
> 
> use Fcntl qw(:flock);
> open($lockfile,">builder.LCK") || die "opening lockfile";
> exit(0) unless flock($lockfile,LOCK_EX|LOCK_NB);

flock on Perl is implemented using platform-dependent system calls.  Per
the docs,
      flock FILEHANDLE,OPERATION              Calls flock(2), or an emulation of it, on FILEHANDLE.  Returns
 true for success, false on failure.  Produces a fatal error if              used on a machine that doesn't implement
flock(2),fcntl(2)              locking, or lockf(3).  "flock" is Perl's portable file locking              interface,
althoughit locks only entire files, not records.
 

Note that it may fail!  This seems to indicate that some platforms do
not provide either locking mechanism.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Improving ALTER TYPE support
Next
From: Alvaro Herrera
Date:
Subject: Re: file-locking and postmaster.pid