Two possibilities: lsof
(my preference) or lslk
(specifically for file locks):
[root@policyServer ~]# lslk | grep "master.lock"
SRC PID DEV INUM SZ TY M ST WH END LEN NAME
master 1650 253,0 12423 33 w 0 0 0 0 0 /var/lib/postfix/master.lock
[root@policyServer ~]# lsof | grep "master.lock"
master 1650 root 10uW REG 253,0 33 12423 /var/lib/postfix/master.lock
Output of lslk is self-expanatory but lsof
puts the lock description in the "FD" column (which is 10uW
above). From the man page:
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.
So the "FD" column of lsof
above breaks down to:
10
The literal descriptor of this open file. What's linked to by /proc/1650/fd/10
u
File is open for reading and writing
W
program has a write lock on the file.
lsof
approach Joel Davis suggests. – mattdm Aug 08 '13 at 18:26lslocks
reads/proc/locks
, in a pinch you can read that directly yourself, with the caveat that files are identified by device and inode rather than name. Since you know the file, that ought not be a problem. Blocked entries have a->
prefix before the lock type column (thus adding a column to that line). – mr.spuratic Aug 09 '13 at 10:34lslocks
showed that the file was locked by a PID that did not exist. Butlsof
pointed out the true culprit, an instance ofssh-agent
¯\(ツ)/¯ it probably got in when I triedflock -c
that launched a shell.. – xealits Dec 13 '21 at 20:48