I have a point of contention on my linux server. One of a number of processes access a single file and lock the file at a random time for a considerable period (>60 seconds) which, in turn, causes other things to fail.
Is there a way to detect how long a file has been locked and by which process?
I think what you are looking for is the file
/proc/locks
. It shows the current file locks in the system. This not shows how long a file has been locked, but it shows by which process. Maybe you could detect when the lock is register in this file and measure the elapsed time. A sample is this:Where the columns are:
fcntl
andFLOCK
if created withflock
.:
that identified the locked file.You can tell how old a lock file is by simply looking at the timestamp when it was created. Similarly if you "cat logfile.name" it will very often have, as its sole contents, the process ID which created it.