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 flushed to disk when the process is killed via SIGKILL, then it will also do so with other terminating signals (SIGABRT, SIGSEGV, etc...).
Asked
Active
Viewed 3,084 times
2 Answers
17
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.

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278
-
Thanks! Do you have any documentation about this behaviour? I couldn't find any. – chila May 14 '09 at 17:48
-
5The POSIX standard (http://www.opengroup.org/onlinepubs/9699919799/toc.htm) for mmap() says: If MAP_SHARED is specified, write references shall change the underlying object. No weasel words about 'unless the process is killed after the memory write completes but before the data is flushed to disk'. – Jonathan Leffler May 14 '09 at 20:23
0
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

Community
- 1
- 1

BD at Rivenhill
- 12,395
- 10
- 46
- 49