http://www.gnu.org/s/libc/manual/html_node/File-Locks.html
Locks are associated with processes. A process can only have one kind of lock set for each byte of a given file. When any file descriptor for that file is closed by the process, all of the locks that process holds on that file are released, even if the locks were made using other descriptors that remain open. Likewise, locks are released when a process exits, and are not inherited by child processes created using fork.
就是说,文件锁是跟进程关联的。如果给一个文件用fcntl加了锁,又用其它方式(打开然后)关闭了这个文件,那么进程就失去这个锁了,尽管加锁的那个fd还在open着!
本文探讨了文件锁与进程之间的关联性。当一个进程为文件设置了锁后,若通过其他方式关闭该文件,则进程会失去对该文件的锁定,即便用于设置锁的文件描述符仍然处于打开状态。此外,当进程退出或创建子进程时,所有文件锁也会被释放。
1743

被折叠的 条评论
为什么被折叠?



