Program memory space allocation in CentOS
Let's take a look at a simple piece of code:
[Cpp] view plaincopy
- # Include <stdio. h>
- # Include <unistd. h>
- Intmain ()
- {
- Printf ("% d \ n", getpid ());
- While (1 );
- }
Running result:
In this case, open another terminal and enter cat/proc/10073/maps. The following figure is displayed:
[Cpp] view plaincopy
- 08048000-08049000r-xp0000fd: 0114844/home/Alex/DaNei/Interview/a. out
- 08049000-0804a000r -- p00000000fd: 0114844/home/Alex/DaNei/Interview/a. out
- 0804a000-0804b000rw-p00001000fd: 0114844/home/Alex/DaNei/Interview/a. out
- 4427b000-4429a000r-xp0000fd: 01393917/usr/lib/ld-2.17.so
- 4429a000-4429b000r -- p0001e000fd: 01393917/usr/lib/ld-2.17.so
- 4429b000-4429c000rw-p0001f000fd: 01393917/usr/lib/ld-2.17.so
- 442a3000-4445b000r-xp5110000fd: 01393918/usr/lib/libc-2.17.so
- 4445b000-4445c000 --- p001b8000fd: 01393918/usr/lib/libc-2.17.so
- 4445c000-4445e000r -- p001b8000fd: 01393918/usr/lib/libc-2.17.so
- 4445e000-4445f000rw-p001ba000fd: 01393918/usr/lib/libc-2.17.so
- 4445f000-44462000rw-p0000000000: 000
- B7752000-b7753000rw-p0000000000: 000
- B7769000-b776b000rw-p0000000000: 000
- B776b000-b776c000r-xp0000000000: 000 [vdso]
- Bfe13000-bfe34000rw-p0000000000: 000 [stack]
In fact, the first line is the memory space occupied by the code area, 804800-804900. In fact, almost all linux program code segments start from 804800, the second row is the memory space occupied by the global stack area, the third row is the memory space occupied by the heap space, and the last row is the memory space occupied by the local stack.
At the same time, we will find that except the code segment's permission is r-xp (readable-writable-executable-private protection), the other three are not executable.