Does the OS (POSIX) flush a memory-mapped file if the process is SIGKILLed?

后端 未结 2 791
陌清茗
陌清茗 2021-01-02 00:04

If a process is killed with SIGKILL, will the changes it has made to a memory-mapped file be flushed to disk? I assume that if the OS ensures a memory-mapped file is flushe

相关标签:
2条回答
  • 2021-01-02 00:08

    It will depend on whether the memory-mapped file is opened with modifications private (MAP_PRIVATE) or not (MAP_SHARED). If private, then no; the modifications will not be written back to disk. If shared, the kernel buffer pool contains the modified buffers, and these will be written to disk in due course - regardless of the cause of death.

    0 讨论(0)
  • 2021-01-02 00:30

    I posed a similar question myself and then followed up with demonstration code when I was unsatisfied with the answers. See mmap, msync and linux process termination

    0 讨论(0)
提交回复
热议问题