2.19、/proc/locks
保 存当前由内核锁定的文件的相关信息,包含内核内部的调试数据;每个锁定占据一行,且具有一个惟一的编号;如下输出信息中每行的第二列表示当前锁定使用的锁 定类别,POSIX表示目前较新类型的文件锁,由lockf系统调用产生,FLOCK是传统的UNIX文件锁,由flock系统调用产生;第三列也通常由 两种类型,ADVISORY表示不允许其他用户锁定此文件,但允许读取,MANDATORY表示此文件锁定期间不允许其他用户任何形式的访问;
[root@rhel5 ~]# more /proc/locks 1: POSIX ADVISORY WRITE 4904 fd:00:4325393 0 EOF 2: POSIX ADVISORY WRITE 4550 fd:00:2066539 0 EOF 3: FLOCK ADVISORY WRITE 4497 fd:00:2066533 0 EOF |
http://www.cnblogs.com/my_life/articles/4540485.html
https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-locks.html
This file displays the files currently locked by the kernel. The contents of this file contain internal kernel debugging data and can vary tremendously, depending on the use of the system. A sample /proc/locks
file for a lightly loaded system looks similar to the following:
1: POSIX ADVISORY WRITE 3568 fd:00:2531452 0 EOF 2: FLOCK ADVISORY WRITE 3517 fd:00:2531448 0 EOF 3: POSIX ADVISORY WRITE 3452 fd:00:2531442 0 EOF 4: POSIX ADVISORY WRITE 3443 fd:00:2531440 0 EOF 5: POSIX ADVISORY WRITE 3326 fd:00:2531430 0 EOF 6: POSIX ADVISORY WRITE 3175 fd:00:2531425 0 EOF 7: POSIX ADVISORY WRITE 3056 fd:00:2548663 0 EOF
Each lock has its own line which starts with a unique number.
- The second column refers to the class of lock used, with
FLOCK
signifying the older-style UNIX file locks from aflock
system call andPOSIX
representing the newer POSIX locks from thelockf
system call.
FLOCK:flock() : flock函数只能对整个文件加锁,不能加记录锁
POSIX: fcntl(): fcntl函数则不仅完全支持加劝告锁与强制锁,还支持记录锁,另外因为它符合POSIX标准,具有很好的可移植性。
- The third column can have two values:
ADVISORY
orMANDATORY
.ADVISORY
means that the lock does not prevent other people from accessing the data; it only prevents other attempts to lock it.MANDATORY
means that no other access to the data is permitted while the lock is held.
ADVISORY: 仅阻止其他进程进行加锁,不会阻止其他进程进行文件的读写。
MANDATORY: 加锁期间,其他进程不能再加锁,也不能进程读写
建议性锁和强制性锁之间的区别,是指其他文件操作函数(如open,read、write)是否受记录锁影响,如果是,那就是强制性的记录锁,大部分平台只是建议性的。不过,对实现进程互斥锁而言,这个影响不大。
- The fourth column reveals whether the lock is allowing the holder
READ
orWRITE
access to the file.
是否允许锁的持有者进行文件读写
- The fifth column shows the ID of the process holding the lock.
- The sixth column shows the ID of the file being locked, in the format of
.MAJOR-DEVICE
:MINOR-DEVICE
:INODE-NUMBER
- The seventh and eighth column shows the start and end of the file's locked region.