Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 330
user1660982 Avatar asked Jul 30 '13 13:07

user1660982


People also ask

What part of the memory segment keeps the program stack?

One segment is used to contain instruction codes, another segment stores the data elements, and a third segment keeps the program stack.

How are programs stored in memory?

When the CPU executes a program, that program is stored in the computer's main memory (also called the RAM or random access memory). In addition to the program, memory can also hold data that is being used or processed by the program.

What are the different memory segments?

After being loaded into the RAM, memory layout in C Program has six components which are text segment, initialized data segment, uninitialized data segment, command-line arguments, stack, and heap. Each of these six different segments stores different parts of code and have their own read, write permissions.


1 Answers

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.

like image 194
Sergey L. Avatar answered Oct 21 '22 03:10

Sergey L.