2

After a process calls fork() with anonymous mapped pages in its address space and the child process modifies the page, does that anonymous mapped page in the child process basically start acting like a memory mapped page?

jww
  • 97,681
  • 90
  • 411
  • 885
  • Also see [Does mmap share memory with all processes?](http://stackoverflow.com/q/11738703/608639), [Sharing memory between processes through the use of mmap()](http://stackoverflow.com/q/4991533/608639), [How to read from /write to anonymous shared mapping?](http://stackoverflow.com/q/31305015/608639), etc. – jww Feb 27 '17 at 07:54

1 Answers1

1

That depends on flags passed to mmap. If MAP_SHARED is specified then mapped pages would be shared. If MAP_PRIVATE, mapped pages would not be shared - each forked process would get its own copy.

MAP_SHARED and MAP_PRIVATE describe the disposition of write references to the memory object. If MAP_SHARED is specified, write references shall change the underlying object. If MAP_PRIVATE is specified, modifications to the mapped data by the calling process shall be visible only to the calling process and shall not change the underlying object. It is unspecified whether modifications to the underlying object done after the MAP_PRIVATE mapping is established are visible through the MAP_PRIVATE mapping. Either MAP_SHARED or MAP_PRIVATE can be specified, but not both. The mapping type is retained across fork().

POSIX.1-2001: mmap