Text: Code snippet. The entire code (instruction) of the stored program, derived from the code portion of the binary executable, is placed in the binary file at compile time.
Initialized data (referred to as data segment) and uninitialized (BSS) Form a segment. Where the data segment holds the initialized global variable and the initialized static local variable, derived from the part of the binary executable, which is already placed in the binary file at compile time, the BSS segment holds uninitialized global variables and uninitialized static local variables. The content does not originate from the data part of the binary executable (that is, the data part of the binary executable does not have an uninitialized global variable and the static local variable is uninitialized). According to the C language standard, their initial value must be 0, so the BSS section is stored in all 0. The work of BSS Chingqing 0 is done by the system after the binary file is loaded, and the system performs this clear 0 operation is a piece of code completed by the kernel (exec system call). As to where exec begins to clear 0 from memory-and to clear 0 less space-it is determined by the information recorded in the binary executable (that is, the size of the text, data, BSS section is recorded in the binary file)
malloc allocates space from the heap.
The stack (stack) holds dynamic local variables. That is, when the child function is called, the system allocates space from the stack to the dynamic local variable of the child function (note: The stack is extended to the memory low address), and when the child function returns, the stack of the system extends to the memory high address, which is equivalent to freeing the memory space of the dynamic local variable of the child function. Assuming that the main function calls sub-function B immediately after calling the child function A, then the dynamic local variables of sub-function B will overwrite the storage space of the dynamic local variables of the original sub-function A, which is the fundamental physical reason that the sub-functions cannot access each other's dynamic local variables.
The top end of the memory is the command line arguments and environment variables, the command line parameters and environment variables are placed in the specified location this operation is a piece of code with the OS (the Exec system call) after loading the binaries into memory, before starting to run the program to complete.
From "Linux C language application Programming"
C Process Memory Layout description