Question

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.

Was it helpful?

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.

OTHER TIPS

Short answer: it depends on the hardware and OS it's running on.

Usually, each process gets its own virtual memory space, giving it the illusion of it seeming like the only process running on the computer. That virtual memory space is divided into code/data/stack segments by the OS (these usually have fixed/common addresses).

As far as physical RAM usage, that depends entirely on the OS - it can use different sections of RAM as it pleases, and the programs won't even know about it.

This question is Operating System specific and not C specific.

In general, OSes maintain an execution context per process, which holds the stack and runtime flags, but how memory is allocated by the likes of malloc varies between systems.

For more information you may wish to delve deeper into the malloc documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top