Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
$ cat /proc/locks
1: POSIX ADVISORY  WRITE 458 03:07:133880 0 EOF
2: FLOCK ADVISORY  WRITE 404 03:07:133879 0 EOF

The fields are: ordinal number(1), type(2), mode(3), type(4), pid(5), maj:min:inode(6) start(7) end(8).

Question: how to find the corresponding file is being locked?

share|improve this question

1 Answer 1

up vote 4 down vote accepted
sudo find -L /proc/458/fd -maxdepth 1 -inum 133880 -print -exec readlink {} \;

To get all of them:

while IFS=': ' read x x x x p x x i x; do
  sudo find -L "/proc/$p/fd" -maxdepth 1 -inum "$i" -exec readlink {} \; -quit
done < /proc/locks

Sometimes, the process whose pid is referenced in /proc/lock will have died. You can change the "/proc/$p/fd" above to /proc/*/fd to look for them among all processes fds.

(note that it is an approximation as we're only checking the inode number, not the device number, but chances that we pick the wrong file (same inum on a different fs) are very slim).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.