Do different programs gets their memory from a common heap or from a separate heap?

后端 未结 3 1995
悲哀的现实
悲哀的现实 2021-02-15 03:23

I am a bit confused how glibc on linux allocates its memory to various program.These are the few questions:

  1. Is it been allocated from a common heap(i.e is there

3条回答
  •  深忆病人
    2021-02-15 03:46

    The heap (and any other writable memory - stack, BSS, etc) is separate for each process. Within the process the memory might be shared between threads, and it might not be (in case of thread local storage). This is true for newly created applications. For fork-ed application, the memory is shared until either process writes to it (copy-on-write).

    Any read-only memory (like a shared library or running the same application multiple times) will probably be shared between the processes. This is a decision for the kernel executable loader.

    A static library is linked directly to the executable, so there is a separate copy for each executable running (unless it's multiple instances of the same executable).

提交回复
热议问题