Memory Management
Each process has one virtual address space, with addresses running from zero to some huge maximum. Virtual memory is divided into pages, usually of 4 kilobytes in size. Paging is the process of managing the virtual memory to real memory translations.
A process' virtual address space is divided into segments. A segment is a contiguous range of virtual addresses. Three important segments are:
- text segment contains a program's instructions
- data segment is working storage for the program.
- stack segment contains a program stack. It grows as the stack grows, but doesn't shrink when the stack shrinks.
main()
{
int j=0;
int k;
int *ptr;
ptr=(int *)malloc(70000*sizeof(int));
while(1)
{
j++;
if(j=100)
j=0;
}
}
00400000-00401000 r-xp 00000000 08:01 137910 /home/jestinjoy/process/a.out00600000-00601000 rw-p 00000000 08:01 137910 /home/jestinjoy/process/a.out00e1a000-00e3b000 rw-p 00000000 00:00 0 [heap]7fd3c3c74000-7fd3c3df4000 r-xp 00000000 08:01 656659 /lib/x86_64-linux-gnu/libc-2.13.so7fd3c3df4000-7fd3c3ff4000 ---p 00180000 08:01 656659 /lib/x86_64-linux-gnu/libc-2.13.so7fd3c3ff4000-7fd3c3ff8000 r--p 00180000 08:01 656659 /lib/x86_64-linux-gnu/libc-2.13.so7fd3c3ff8000-7fd3c3ff9000 rw-p 00184000 08:01 656659 /lib/x86_64-linux-gnu/libc-2.13.so7fd3c3ff9000-7fd3c3ffe000 rw-p 00000000 00:00 07fd3c3ffe000-7fd3c401e000 r-xp 00000000 08:01 656662 /lib/x86_64-linux-gnu/ld-2.13.so7fd3c41fd000-7fd3c4200000 rw-p 00000000 00:00 07fd3c421b000-7fd3c421d000 rw-p 00000000 00:00 07fd3c421d000-7fd3c421e000 r--p 0001f000 08:01 656662 /lib/x86_64-linux-gnu/ld-2.13.so7fd3c421e000-7fd3c421f000 rw-p 00020000 08:01 656662 /lib/x86_64-linux-gnu/ld-2.13.so7fd3c421f000-7fd3c4220000 rw-p 00000000 00:00 07fffc3c01000-7fffc3c22000 rw-p 00000000 00:00 0 [stack]7fffc3cb8000-7fffc3cb9000 r-xp 00000000 00:00 0 [vdso]ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]The first two regions refer to the code and data and then we have heap region. After we have regions based on standard C library which is specified by the files in /lib. After that we have stack segment and segments which is used for system calls.