What happens if a write system call is called on same file by 2 different processes simultaneously

前端 未结 5 1154
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 05:53

Does the OS handle it correctly?

Or will I have to call flock()?

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 06:19

    Of course the kernel will handle it correctly, for the kernel’s idea of correctness — which is by definition correct.

    If you have a set of coöperating flockers, then you can use the kernel to queue everyone up. But remember that flock has nothing to do with I/O: it will not stop someone else from writing the file. It will at most only interfere with other flockers.

提交回复
热议问题