Ben*_*ird 72 process lock files
使用flock,多个进程可以同时拥有一个共享锁,或者等待获取一个写锁。我如何获得这些进程的列表?
也就是说,对于给定的文件 X,理想情况下找到每个进程的进程 ID,该进程持有或正在等待文件锁定。尽管只是计算等待锁定的进程数,但这将是一个非常好的开始。
mat*_*tdm 62
lslocks,来自util-linux 包,正是这样做的。
在该MODE列中,等待锁定的进程将被标记为*。
Bra*_*ley 34
两种可能性:(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
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
所以上面的“FD”列lsof分解为:
10此打开文件的文字描述符。与什么相关联/proc/1650/fd/10
u 文件已打开以供读取和写入
W 程序对文件有写锁。
小智 5
lsof 可以帮助查看文件列表。这是查看锁定文件的方法。
sudo lsof /var/lib/dpkg/lock
Run Code Online (Sandbox Code Playgroud)