On 5/29/07, Akbar Ehsan <[EMAIL PROTECTED]> wrote:
Hello Everyone,

I am attempting to lock a file using FLOCK. I understand the FLOCK is an
advisory lock and that it does not prevent any other process/program
from "clobbering" the file even when the lock in on the file.

Is there anything I should look into to apply a lock on a file so that
it does not get written to when the lock is in place?

Any thoughts or ideas would be appreciated.

Thanks.


Akbar,

The short answer is "no." There really is no such thing as mandatory
file locking, at least not from a program's point of view. If you have
complete control over the execution environment, most operating
systems support some kind of sticky bit which, combined with specific
mount flags on a given volume, can enforce mandatory locks. But unless
you are writing tour program to run on one specific machine that you
and you alone administer, there is no silver bullet here.

If concurrent writes are really something you're worried about, your
best bets are, as others have suggested, to configure your program to
use a database that enforces locks or supports row locking, or to use
a client-server approach where all writes are dispatched to a single
writer process that serializes the write requests before committing
them to disk.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to