[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: flock, fcntl, lockf?



On 2008-01-14 23:50:35 +0000, Hendrik Boom wrote:
> On Mon, 14 Jan 2008 08:17:53 -0900, Ken Irving wrote:
> > My impression is that file locking is based on all participants following
> > the same convention, whatever it is, so the right way would be whatever
> > other programs that might be operating on the same files are doing.
> 
> Yes.  Exactly.  I'm writing new software, so I have a bit of a choice.  My
> question involves both technical issues and the latest fashion trends in
> the file locking community.

I tend to use fcntl because it is NFS safe and when the program dies
for whatever reason (even kill -9, which is not trappable to explicitly
remove the lock), the lock disappears. Another very important advantage
(this is sometimes necessary) is that NFS cache problems are avoided on
the locked file. But depending on the context, one doesn't always want
the lock to disappear if the program couldn't do the necessary clean-up
first (there are other ways to deal with that, though).

I also use symlink locking, which is also NFS safe, mainly in my shell
scripts, because this is quite easy in this context. And one can put
interesting information in the symlink contents (the symlink doesn't
have to point to a real file). See what Firefox does for instance (the
lock is in the profile).

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


Reply to: