Unix questions - Re: Anybody have any experience with locking/unlocking files using

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > September 2005 > Re: Anybody have any experience with locking/unlocking files using





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Anybody have any experience with locking/unlocking files using
Steffen

2005-09-02, 2:55 am

Hi,

doomster@gmail.com wrote:
> So shouldn't they return a Read Lock (F_RDLCK) rather than a F_UNLCK?
>
> You're right - Read Locks don't interfere with each other. But they do
> interfere with an exclusive (Write) Lock.
>
> This still doesn't sound right. A file locked with a Read lock should
> return F_RDLCK if a F_GETLK command was issued against it.


One could say that the name GETLCK is a bit misleading, since it does
not necessarily return the lock status of a file. What happens depends
on the l_type of the lock structure you pass on to GETLCK.

Upon calling GETLCK, you have to specify a valid lock in the structure.
If it would be possible to place that look (it is not actually placed,
it is just tested if it would be possible), the status you get back in
the structure is UNLCK.

Assume there already is a read lock on a file (from another process) and
you call GETLCK with l_type=RDLCK. Since it would be possible to place
that lock (there can be any number of read locks) you get back
l_type=UNLCK - even if there already is a read lock on the file.

If you called GETLCK with l_type=WRLCK, this lock could not be placed
since it is incompatible with the already existing read lock. Then the
lock structure reports back that already existing lock, namely l_type=RDLCK.

One may find that illogical, but that just is the way fcntl works.


Steffen

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com