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(同一进程打开同一份文件多次时,进程会得到不同的fd) 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. (如果此时用其中一个fd对文件进行加锁,当进程利用fd来close文件,不管是加锁使用过的fd,还是其他fd,都会造成进程加的文件锁被释放掉,尽管此时可能加锁使用的fd还没close文件.但是只要是同一进程,该文件被关了,锁就会被释放.) Likewise, locks are released when a process exits, and are not inherited by child processes created using fork.(这个就跟第一句呼应,毕竟跟进程相关,子进程就算是fork出来了,子进程不是父进程)
文件锁的问题
最新推荐文章于 2024-11-29 20:13:27 发布