Re: file-locking and postmaster.pid

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: 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: 2006-05-24 20:30:12
Message-ID: 4474C254.2090801@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera wrote:
> korry wrote:
>
>
>> The only platform (although certainly not a minor issue) that I can
>> think of that would have a portability issue would be Win32. You can't
>> even read a locked byte in Win32. I usually solve that problem by
>> locking a byte past the end of the file (which is portable).
>>
>
> Certainly on all platforms there must be *some* locking primitive. We
> just need to figure out the appropiate parameters to fcntl() or flock()
> or lockf() on each.
>
> The Win32 API for locking seems mighty strange to me.
>
>

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);

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2006-05-24 20:34:40 Re: file-locking and postmaster.pid
Previous Message korry 2006-05-24 20:19:33 Re: file-locking and postmaster.pid