Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: file-locking and postmaster.pid


  • From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
  • To: Andrew Dunstan <andrew(at)dunslane(dot)net>
  • Cc: korry <korry(at)appx(dot)com>, Andreas Joseph Krogh <andreak(at)officenet(dot)no>, pgsql-hackers(at)postgresql(dot)org
  • Subject: Re: file-locking and postmaster.pid
  • Date: Wed, 24 May 2006 16:36:54 -0400
  • Message-id: <20060524203654(dot)GB6607(at)surnet(dot)cl>

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, although it 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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group