On many Unix systems, the marvelous lsof utility provides vast amounts of information about what your processes are doing.
One part of that information is supposed to include details about the locks that are held on the open files:
The mode character is followed by one of these lock characters, describing the type of lock applied to the file:
N for a Solaris NFS lock of unknown type;
r for read lock on part of the file;
R for a read lock on the entire file;
w for a write lock on part of the file;
W for a write lock on the entire file;
u for a read and write lock of any length;
U for a lock of unknown type;
x for an SCO OpenServer Xenix lock on part of the file;
X for an SCO OpenServer Xenix lock on the entire file;
space if there is no lock.
On Linux, at least, this works great; I see the lock characters as I expect.
On Mac OS X, though, I never see those lock characters.
When I look at a recent copy of the FAQ, I see a note about NEXTSTEP:
12.0 NEXTSTEP and OPENSTEP Problems
12.1 Why can't lsof report on 3.1 lockf() or fcntl(F_SETLK) locks?
Lsof has code to test for locks defined with lockf() or fcntl(F_SETLK) under NEXTSTEP 3.1, but that code has never been tested. I couldn't test it, because my NEXTSTEP 3.1 lockf() and fcntl(F_SETLK) functions return "Invalid argument" every way I have tried to invoke them.
I'm not sure if this section applies to the Mac OS X version of lsof, or not.
For yucks, I tried looking at the source, and it sure looks like the implementation retrieves the access mode and turns it into 'r', 'w', or 'u', appropriately, and also retrieves the file size and type information, but there doesn't appear to be any code to fetch the lock information.
And, of course, I can't get it to work on my Mac (I appear to be running lsof 4.82 on Mac OS X 10.6.8, if that's relevant).
Does anybody know? Does this work?