Let's take a look at a simple piece of code: [cpp] viewplaincopy # include & lt; stdio. h & gt; # include & lt; unistd. h & gt;
Let's take a look at a simple piece of code:
[Cpp]View plaincopy
- # Include
- # Include
- Int main ()
- {
- 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-08049000 r-xp 00000000 fd: 01 14844/home/Alex/DaNei/Interview/a. out
- 08049000-0804a000 r -- p 00000000 fd: 01 14844/home/Alex/DaNei/Interview/a. out
- 0804a000-0804b000 rw-p 00001000 fd: 01 14844/home/Alex/DaNei/Interview/a. out
- 4427b000-4429a000 r-xp 00000000 fd: 01 393917/usr/lib/ld-2.17.so
- 4429a000-4429b000 r -- p 0001e000 fd: 01 393917/usr/lib/ld-2.17.so
- 4429b000-4429c000 rw-p 0001f000 fd: 01 393917/usr/lib/ld-2.17.so
- 442a3000-4445b000 r-xp 00000000 fd: 01 393918/usr/lib/libc-2.17.so
- 4445b000-4445c000 --- p 001b8000 fd: 001 393918/usr/lib/libc-2.17.so
- 4445c000-4445e000 r -- p 001b8000 fd: 01 393918/usr/lib/libc-2.17.so
- 4445e000-4445f000 rw-p 001ba000 fd: 01 393918/usr/lib/libc-2.17.so
- 4445f000-44462000 rw-p 00000000 00:00 0
- B7752000-b7753000 rw-p 00000000 0
- B7769000-b776b000 rw-p 00000000 0
- B776b000-b776c000 r-xp 00000000 0 [vdso]
- Bfe13000-bfe34000 rw-p 00000000 0 [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.