I am essentially trying to "tail" a file by using a memory mapped file within a reader process while a writer process is appending data to it (using stdio) at some time interval.
My question is how does the synchronization between the memory mapped file and the writer work behind the scenes? Would I need any additional synchronization mechanisms?
I could use inotify to find out when the file is modified but I wasn't sure if the memory mapped file is guaranteed to be updated as well.
I am using Linux ubuntu with gcc 4.8.2.
If you are writing into a memory-mapped file, the file be backed up to disk in the following cases (I assume you mapped the file with MAP_SHARED
):
msync
(see http://man7.org/linux/man-pages/man2/msync.2.html ) munmap
(see http://man7.org/linux/man-pages/man2/munmap.2.html In either case, you should use msync
to flush the data to disk and notify any programs watching on the file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.