File open'ness

Is there a way to know if a File is already opened (by any process, be it the actual process or other processes) on OS X? Does OS X actually give this possibility?

i have to say i was wondering about file locking on osx, this is what i found:

http://developer.apple.com/technotes/tn/tn2037.html

i don’t know if this is implemented in File.

from what i see here to check if a file is already opened, kust try to open it in exclusive mode, and it will propably fail with an error, and you will know.

I already read that Technote. What they are describing there is a cooperative locking mechanism that only works for the applications that participate, called “advisory locking”.

On OS X, there is no way to “definitively” lock a file like on windows, where your application can be the only one still being able to access the file.

I think it is also not possible to find out if the file is open by another process or not.

it has to be possible since osx has lsof

http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man8/lsof.8.html

and underneath all that gui stuff os osx is the bsd kernel.