简体   繁体   English

Linux中的fcntl字节文件锁定

[英]fcntl bytes file locking in linux

I have lock on particular bytes in file using fcntl with some values of fl.1_start and f1.1_len. 我使用fcntl和fl.1_start和f1.1_len的某些值来锁定文件中的特定字节。 while program is running, i tried to write into that file from other program on those bytes. 当程序运行时,我试图从其他程序的那些字节上写入该文件。 when both programs running simultaneously, second program is writing into those locked bytes despite lock present from first program. 当两个程序同时运行时,尽管第一个程序存在锁定,第二个程序仍将写入那些锁定的字节。 can anyone explain why it is behaving like that? 谁能解释为什么它会那样?

fcntl is kind of voluntary implementation in Unix like systems. fcntl是类Unix系统中的自愿实现。 Both processes have to use it in order to work correctly. 这两个过程都必须使用它才能正常工作。

Operations like read() and write() simply ignore locks. read()write()只会忽略锁。 The other process is blocked only when explicitly calling fcntl() on the area which is already locked by other process 仅当在已被其他进程锁定的区域上显式调用fcntl()时,另一个进程才被阻止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM