Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the virtual memory structure of processes under Linux?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what is the process virtual memory structure under Linux". In daily operation, I believe that many people have doubts about what the process virtual memory structure is under Linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the process virtual memory structure under Linux?" Next, please follow the editor to study!

PostgreSQL uses the process architecture, and each connection corresponds to a background process. In order to better understand this architecture, it is necessary to deeply understand the relevant knowledge of the process.

1. Virtual memory

The detailed structure of the process virtual memory is shown in the following figure:

The C sample program is as follows:

# include # include # include / * f-print locations of various elements * * Returns: nothing * / void f (void) / / subfunction {int a Int b; int c; a = 98; b = 1024; c = a * b; printf ("[f] a =% d, b =% d, c = a * b =% d\ n", a, b, c); printf ("[f] Adresses of a:% p, b =% p, c =% p\ n", (void *) & a, (void *) & b, (void *) & c) } / * * main-print locations of various elements * * Return: EXIT_FAILURE if something failed. Otherwise EXIT_SUCCESS * / int main (int ac, char * * av, char * * env) {int int i; int size; printf / local variable, located in the stack void * p * int i; int size; printf / pointer, allocates memory in the heap int i; int size; printf ("Address of a:% p\ n", (void *) & a); p = malloc (98) / / allocate memory if (p = = NULL) {fprintf (stderr, "Can't malloc\ n"); return (EXIT_FAILURE);} printf ("Allocated space in the heap:% p\ n", p); printf ("Address of function main:% p\ n", (void *) main) / / the memory address of the main function printf ("First bytes of the main function:\ n\ t"); for (I = 0; I

< 15; i++) { printf("x ", ((unsigned char *)main)[i]);//首16个字节 } printf("\n"); printf("Address of the array of arguments: %p\n", (void *)av);//输入参数数组地址 printf("Addresses of the arguments:\n\t");// for (i = 0; i < ac; i++) { printf("[%s]:%p ", av[i], av[i]);//打印输入参数 } printf("\n"); printf("Address of the array of environment variables: %p\n", (void *)env);//环境变量地址 printf("Address of the first environment variables:\n");//环境变量信息 for (i = 0; i < 3; i++) { printf("\t[%p]:\"%s\"\n", env[i], env[i]); } /* size of the env array */ i = 0; while (env[i] != NULL)//以NULL作为终结 { i++; } i++; /* the NULL pointer */ size = i * sizeof(char *); printf("Size of the array env: %d elements ->

% d bytes (0x%x)\ n ", I, size, size); / / calculate the environment variable array size f (); / / call the function getchar (); / / accept input, and the process does not exit return (EXIT_SUCCESS);}

Compile and execute

[root@localhost hacker] # gcc-Wall-Wextra-Werror main-7.c-o 7 [root@localhost hacker] #. / 7 Hello Hacker jackpot address of a: 0x7fff5b327bb8-- > in the stack Allocated space in the heap: 0x9b6010-- > in the heap Address of function main: 0x400729-- > executable First bytes of the main function: 55 48 89 e5 48 83 ec 40 89 7d dc 48 89 75 d 0 Address of the array of arguments: 0x7fff5b327cb8-- > parameter array address Addresses of The arguments: [. / 7]: 0x7fff5b329808 [Hello]: 0x7fff5b32980c [Hacker]: 0x7fff5b329812 [Jack!]: 0x7fff5b329819-- > input parameter Address of the array of environment variables: 0x7fff5b327ce0-- > Environment variable array Address of the first environment variables: [0x7fff5b32981f]: "XDG_SESSION_ID=1" [0x7fff5b329830]: "HOSTNAME=localhost.localdomain" [0x7fff5b32984f]: "SELINUX_ROLE_REQUESTED=" Size of the array env: 27 elements-> 216 bytes (0xd8) [f] a = 98 B = 1024, c = a * b = 100352 [f] Adresses of a: 0x7fff5b327b7c, b = 0x7fff5b327b78, c = 0x7fff5b327b74-- > variable address in function f

The assembly code can be decompiled by udis86.

[root@localhost install] # echo "55 4889e5 4883ec10 488d45f0 4889c6" | udcli-64-x-o 40072900000000400729 55 push rbp 0000000040072a 4889e5 mov rbp, rsp 0000000040072d 4883ec10 sub rsp, 0x10 00000000400731 488d45f0 lea rax, [rbp-0x10] 00000000400735 4889c6 mov rsi, rax [root@localhost install] #

View the memory mapping information for this process

[root@localhost install] # ps aux | grep ". / 7" | grep-v greproot 6471 0.0 4348 348 pts/0 S+ 15:24 0:00 / 7 Hello Hacker Jack! [root@localhost install] # cat / proc/6471/maps00400000-00401000 r-xp 00000000 fd:00 134287606 / data/source/hacker/700600000-00601000 Rashi p 00000000 fd:00 134287606 / data/source/hacker/700601000-00602000 rw-p 00001000 fd:00 134287606 / data/source/hacker/7009b6000-009d7000 rw-p 00000000 00:00 0 [heap] 7f95b5d16000-7f95b5ed8000 r-xp 00000000 fd:00 151914 / usr/lib64/libc-2.17.so7f95b5ed8000-7f95b60d8000-p 001c2000 fd:00 151914 / usr/lib64/libc-2.17.so7f95b60d8000-7f95b60dc000 Rmurmurp 001c2000 fd:00 151914 / usr/lib64/libc-2.17.so7f95b60dc000-7f95b60de000 rw-p 001c6000 fd:00 151914 / usr/lib64/libc-2.17.so7f95b60de000-7f95b60e3000 rw-p 00000000 00:00 0 7f95b60e3000-7f95b6105000 r-xp 00000000 fd:00 151907 / usr/lib64/ld -2.17.so7f95b62f8000-7f95b62fb000 rw-p 00000000 00:00 0 7f95b6301000-7f95b6304000 rw-p 00000000 00:00 0 7f95b6304000-7f95b6305000 Ruki p 00021000 fd:00 151907 / usr/lib64/ld-2.17.so7f95b6305000-7f95b6306000 rw-p 00022000 fd:00 151907 / usr/lib64/ld-2.17.so7f95b6306000-7f95b6307000 rw-p 00000000 00:00 0 7fff5b309000-7fff5b32a000 rw-p 00000000 00:00 0 [stack] 7fff5b3f1000-7fff5b3f3000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] [root@localhost install] # so far The study on "what is the virtual memory structure of the process under Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report