Nazeem
Nazeem

Reputation: 59

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. 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?

Upvotes: 0

Views: 227

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

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

Upvotes: 3

Related Questions