Get the App
SLTechnology News&Howtos  ›  Servers  › 

Example Analysis of Program memory Space allocation under CentOS

Shulou Source: shulou.com Published: 2022-06-01 19:26:34 11月15日 Update

Editor to share with you the CentOS program memory space allocation example analysis, I believe that most people do not know much, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

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

[cpp] view plaincopy views the code chip derived to my code chip # include # include int main () {printf ("% d\ n", getpid ()) on CODE; while (1);}

Running result:

At this time, open another terminal, type cat / proc/10073/maps, and the following display appears:

[cpp] view plaincopy views the code chip derived from my code chip on CODE 08048000-08049000 r-xp 00000000 fd:01 14844 / home/Alex/DaNei/Interview/a.out 08049000-0804a000 Rafael 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 3917 / usr/lib/ld -2.17.so 4429a000-4429b000 Rmurmurp 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:01 393918 / usr/lib/libc-2.17.so 4445c000-4445e000 Rmuri 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 00:00 0 b7769000-b776b000 rw-p 00000000 00:00 0 b776b000-b776c000 r-xp 00000000 00:00 0 [vdso] bfe13000-bfe34000 rw-p 00000000 00:00 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 line is the memory space occupied by the global stack area, the third line is the memory space occupied by the heap space, and the last line is the memory space occupied by the local stack.

At the same time, we will find that except that the permission of the code snippet is r-xp (readable-unwritable-executable-private protection), the other three are unexecutable.

The above is all the contents of the article "sample Analysis of Program memory Space allocation under CentOS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code space memory programs articles examples analysis allocation one line content actual actually three not much global at the same time most local more permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Xiaomi macOS Linux