Reputation: 1708
Assume a situation where a program opens a memory mapped file for writing. Immediately after writing the content to the file, it calls exit(0). Now my question is what does the kernel does in this case ? Does it flushes the content of the memory mapped region to the file while closing the file descriptor or it discards what is in the buffer ?
Upvotes: 2
Views: 86
Reputation: 229204
Neither. It does not discard the data. The data mapped through the file/page cache in the kernel, and will be flushed to the disk at a time the kernel finds convenient (or until your program explicitly issues an msync() call). This is pretty much the same as what happens if you do normal write() on a file descriptor, and close() that file descriptor, or exit the program.
Keep in mind, access to that file goes through the same kernel cache, so other processes will see the data you've written immediately whether the process crashes or not. (subject perhaps to memory barriers though).
Upvotes: 2