[fpc-pascal] File locking/protection in Linux

Tony Pelton tpelton at gmail.com
Wed Nov 2 14:44:29 CET 2005


On 11/2/05, Michael Van Canneyt <michael at freepascal.org> wrote:
> On Wed, 2 Nov 2005, Antal wrote:
>
> > How can be avoided in Linux the file corruption due to simultaneous write
> > access from two different process?
>
> Nothing prevents a third process from using the file without locks.

that was what i thought too.

but that link i posted seemed to imply that, if you mounted the
filesystem with an extra flag, that the kernel would cause any regular
process to wait for access to files, if those files had been "flocked"
by any one process, so it then only takes 1 process using the "flock"
calls to get exclusive access.

from the link :

"In these cases, you can enforce locking at the kernel level with
mandatory locks. Mandatory locking is implemented on a file-by-file
basis. When a program attempts to lock a file with lockf or fcntl
that has mandatory locking set, the kernel will prevent all other
programs from accessing the file.[1] Processes which use flock will
not trigger a mandatory lock."

>
> Michael.

Tony



More information about the fpc-pascal mailing list