Yes, the child will retain the parent mappings. Typically, a Linux virtual memory system will actually share a page between two processes until it tries to write new data. At this point, a copy will be made, and each process will have its own unique version - on a different physical address, but keeping the same virtual address. This is called “copy-on-write” and is a significant advantage of efficiency and resources over systems that cannot support this, in particular for running code that often plugs.
Address space layout (ASLR) ranking cannot be applied to libraries or objects that have already assigned virtual addresses, as this will break any pointers contained anywhere in the code - it’s something that the system working with the wrong code, t enough to know about it.
Since all previously constructed objects already exist in memory, constructors are not called again just because of the fork. Any objects that should be duplicated, because they are uniquely modified, made it invisibly by the VM system behind the scenes - they really don’t know that they are cloned, and you could well get a couple of objects, part of the implementation continues to share the physical page with identical contents, while the other part was invisibly bifurcated into separate physical pages with different contents for each process.
You also asked about threads, and this is an area where things get complicated. As a rule, only a stream called fork () will exist in living form in the child element (although data belonging to others will exist in general comparisons, since it is not known what can be used for a branched stream). If you need to try to develop a multi-threaded program, you will need to see the documentation about your streaming implementation. For a general implementation of pthreads on Linux, pay attention to pthread_atfork ()
source share