Answers:
lslocks,来自util-linux软件包,正是这样做的。
在该MODE列中,等待锁定的进程将用标记*。
lsofJoel Davis建议的方法。
lslocks读取时/proc/locks,您可以在需要时直接读取内容,但请注意,文件是通过设备和索引节点而不是名称来标识的。既然您知道文件,那应该没问题。被阻止的条目->在锁类型列之前有一个前缀(因此在该行中添加了列)。
两种可能性:(lsof我的偏爱)或lslk(专门用于文件锁定):
[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
lslk的输出是自扩展的,但是lsof将锁描述放在“ FD”列中(在10uW上方)。从手册页:
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.
因此,lsof上面的“ FD”列细分为:
10此打开文件的文字描述符。链接到什么/proc/1650/fd/10
u 文件已打开以进行读写
W 程序对文件具有写锁定。
flock!您的grep可能会错过锁,例如帖子中的锁(更不用说第一个字段是程序名称了……)
lsof可以帮助您查看文件列表。这是查看锁定文件的方法。
sudo lsof /var/lib/dpkg/lock