Re: Questions about file-locking
From: David Schwartz (davids_at_webmaster.com)
Date: Tue, 13 Apr 2004 15:12:57 -0700
"Luca T." <firstname.lastname@example.org> wrote in message
> Lewin A.R.W. Edwards wrote:
>> man 2 flock
>> "flock(2) places advisory locks only; given suitable permissions on a
>> file, a process is free to ignore the use of flock(2) and perform I/O
>> on the file."
>> fcntl mandatory locking is _possibly_ a better choice, though
> It doesn't really matter to me if it is mandatory or not... I only need it
> to avoid possible problems between two programs that i wrote. If i have
> understood well fcntl is used to lock only a piece of the file, not the
> whole file, this is why i chose flock and not fcntl and my file must go in
> /etc which is not (normally) an NFS drive.
It doesn't matter what you lock so long as both programs try to lock the
same thing before accessing the file. Locking the first byte of the file is
just fine. You can lock the first byte even if the file is empty.