Program memory space allocation in CentOS

Source: Internet
Author: User
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
  1. # Include
  2. # Include
  3. Int main ()
  4. {
  5. Printf ("% d \ n", getpid ());
  6. While (1 );
  7. }

Running result:

 

 

In this case, open another terminal and enter cat/proc/10073/maps. The following figure is displayed:

 

[Cpp]View plaincopy
  1. 08048000-08049000 r-xp 00000000 fd: 01 14844/home/Alex/DaNei/Interview/a. out
  2. 08049000-0804a000 r -- p 00000000 fd: 01 14844/home/Alex/DaNei/Interview/a. out
  3. 0804a000-0804b000 rw-p 00001000 fd: 01 14844/home/Alex/DaNei/Interview/a. out
  4. 4427b000-4429a000 r-xp 00000000 fd: 01 393917/usr/lib/ld-2.17.so
  5. 4429a000-4429b000 r -- p 0001e000 fd: 01 393917/usr/lib/ld-2.17.so
  6. 4429b000-4429c000 rw-p 0001f000 fd: 01 393917/usr/lib/ld-2.17.so
  7. 442a3000-4445b000 r-xp 00000000 fd: 01 393918/usr/lib/libc-2.17.so
  8. 4445b000-4445c000 --- p 001b8000 fd: 001 393918/usr/lib/libc-2.17.so
  9. 4445c000-4445e000 r -- p 001b8000 fd: 01 393918/usr/lib/libc-2.17.so
  10. 4445e000-4445f000 rw-p 001ba000 fd: 01 393918/usr/lib/libc-2.17.so
  11. 4445f000-44462000 rw-p 00000000 00:00 0
  12. B7752000-b7753000 rw-p 00000000 0
  13. B7769000-b776b000 rw-p 00000000 0
  14. B776b000-b776c000 r-xp 00000000 0 [vdso]
  15. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.