Search code examples
operating-systemexecutablememory-segmentation

Does Each program has its own separate segments (code, stack, data) in memory?


Say there are many programs running at the same time.
Does each executable program that runs has its own code, data, and stack segment in RAM or is the complete RAM divided into 4 segments and each of theses segments holds respective segments for each programs.


Solution

  • This depends on two things:

    • Your deployment architecture
    • Your OS that runs your process

    If you are running on x86 on common mainstream Linux, Windows, BSD then

    • each process has it's own private virtual RAM
    • All segments text (code), heap, data are in the same logical address space (virtual RAM segment)

    Historically x86 was designed with the ability to support segmented memory, but OSes never made use of it and support for it was initially dropped in AMD64. Though recent Processors support it again for use in virtualisation and Hypervisors. Userland applications are commonly deployed without segmentation today.