Search code examples
c++cmmap

What happens if two distinct processes use mmap to map the same region of file (one with MAP_SHARED, another with MAP_PRIVATE)?


Can two distinct(not parent/child) processes use mmap to map the same region of file, the process A with flag MAP_SHARED, the process B with MAP_PRIVATE)? If process A changes something in the region, can the process B see it?


Solution

  • Then A gets the file mapped and B gets the file mapped but any writes will not be written back to the file.

    From the manpage:

    It is unspecified whether changes made to the file after the mmap() call are visible in the mapped region.