I agree locking is neededb but the proposal is not simple enough for me. Leave the details to the OS and just use fcntl(). Use F_SETLK to set the lock, and if if that fails use F_GETLK to get the pid of the process holding the lock. Given that failure would be a rare event it is enough to report the pid of the other process.
Just my 2 cents. Martin
