[PLUG] file locking
harigov at gmail.com
Sun Jul 19 11:17:28 PDT 2009
2009/7/17 Vishal Rao <vishalrao at gmail.com>
> On Thu, Jul 16, 2009 at 2:58 PM, Aditya Godbole <aag.lists at gmail.com>
> > On Tue, Jul 14, 2009 at 11:59 AM, Manas Alekar<maalekar at gmail.com>
> > >
> > > You might be interested in mandatory file locking via setgid. Mount
> > > using option mand and then use lockf. There are pitfalls, though.
> > I am looking at a user level approach, not a programmer level approach.
> As far as I understand, file locking calls may not guarantee a lock
> depending on the OS and/or filesystem. Even if you call for and "obtain" an
> exclusive lock (call returns success code) another program can ignore it
> write to the file anyway.
> For a user level (requires cooperation) approach, assume you have the same
> app sharing files in the same folder, then this app co-operates with other
> instances by always calling for exclusive lock, then NOT working on the
> until it can gain the lock.
> Isn't this why we see many apps creating ".lock" type files in their common
Using .lock files is another way of locking a process. For ex., if a program
wants to restrict user from starting multiple instances of itself, it could
possibly create lock files and check for them whenever it starts. It does
prevent the process from restarting when it hangs. Any smart application
developer will create the lock file and then unlock it so that the file will
automatically get deleted when the process exits, so it works even if the
process crashes unless it hangs.
Whatever words we utter should be chosen with care for people will hear them
and be influenced by them for good or ill. - Gautama Buddha
More information about the plug-mail