fcntl bytes file locking in linux

209 views Asked by At

I have lock on particular bytes in file using fcntl with some values of fl.1_start and 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?

1

There are 1 answers

1
Zbynek Vyskovsky - kvr000 On BEST ANSWER

fcntl is kind of voluntary implementation in Unix like systems. Both processes have to use it in order to work correctly.

Operations like read() and write() simply ignore locks. The other process is blocked only when explicitly calling fcntl() on the area which is already locked by other process