Program memory space allocation in CentOS

Source: Internet
Author: User

Program memory space allocation in CentOS

Let's take a look at a simple piece of code:

[Cpp] view plaincopy
  1. # Include <stdio. h>
  2. # Include <unistd. h>
  3. Intmain ()
  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-08049000r-xp0000fd: 0114844/home/Alex/DaNei/Interview/a. out
  2. 08049000-0804a000r -- p00000000fd: 0114844/home/Alex/DaNei/Interview/a. out
  3. 0804a000-0804b000rw-p00001000fd: 0114844/home/Alex/DaNei/Interview/a. out
  4. 4427b000-4429a000r-xp0000fd: 01393917/usr/lib/ld-2.17.so
  5. 4429a000-4429b000r -- p0001e000fd: 01393917/usr/lib/ld-2.17.so
  6. 4429b000-4429c000rw-p0001f000fd: 01393917/usr/lib/ld-2.17.so
  7. 442a3000-4445b000r-xp5110000fd: 01393918/usr/lib/libc-2.17.so
  8. 4445b000-4445c000 --- p001b8000fd: 01393918/usr/lib/libc-2.17.so
  9. 4445c000-4445e000r -- p001b8000fd: 01393918/usr/lib/libc-2.17.so
  10. 4445e000-4445f000rw-p001ba000fd: 01393918/usr/lib/libc-2.17.so
  11. 4445f000-44462000rw-p0000000000: 000
  12. B7752000-b7753000rw-p0000000000: 000
  13. B7769000-b776b000rw-p0000000000: 000
  14. B776b000-b776c000r-xp0000000000: 000 [vdso]
  15. 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.

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.