fcntl, lockf, which is better to use for file locking?

后端 未结 5 1410
春和景丽
春和景丽 2020-11-28 21:32

Looking for information regarding the advantages and disadvantages of both fcntl and lockf

5条回答
  •  生来不讨喜
    2020-11-28 21:40

    As you're only coding a daemon which uses it for mutual exclusion, they are equivalent, after all, your application only needs to be compatible with itself.

    The trick with the file locking mechanisms is to be consistent - use one and stick to it. Varying them is a bad idea.

    I am assuming here that the filesystem will be a local one - if it isn't, then all bets are off, NFS / other network filesystems handle locking with varying degrees of effectiveness (in some cases none)

提交回复
热议问题