This is mainly in the C language, for example, other languages developed programs, each process will have a similar space. Here is a C code:
#include <stdlib.h>#include<stdio.h>Doublet[0x02000000];voidsegments () {Static ints = the; void*p =malloc(2); printf ("stack\t%010p\nbrk\t%010p\nheap\t%010p\n" "static\t%010p\nstatic\t%010p\ntext\t%010p\n", &p, SBRK (0),p,t,&s,segments);}voidWritefreespace () {Char*p = SBRK (0) -1; *p =1; printf ("Assign to SBRK (0)-1 is succed! \ n"); P= SBRK (0) +1; *p =1; printf ("Assign to SBRK (0) +1 is succed! \ n");}intMainintargcChar*argv[]) {segments (); Writefreespace (); Exit (0);}
This is mainly printed here: The address of the pointer p (stack), the position of the current break of the process (the bounds of the heap), the address (heap) that the pointer p points to, the address of the global variable T, the address of the local static variable, and the address of the function segments ().
After using GCC, the result of this code is as follows:
Stack 0xbfaa9edcbrk 0x18856000heap 0x18835008 Static 0x0804a060static 0x0804a024text 0x08048494Size of Heap:20ff8 Assign to SBRK (0)-1 is succed! Segmentation Fault
This is a good proof of the distribution in the relationship:
Among them, the SBRK () function may not be common. In general, it is not recommended to use SBRK () when applying programming, so we do not have the least. By man, sbrk (int) is used to increase the size of the heap, when it is fed parameter 0, it returns the heap boundary (SBRK (0) returns the address already in the heap (), can change the address in the writefreespace () attempt; As can be seen, the minimum heap value is 132k Bytes (20ff8+8=21000), the first 8 byte is reserved, the specific role needs to be understood again.
Memory space allocation for processes under Linux