Virt Res SHR Data These are easy to confuse.
First explain the following meanings:
Virt: Virtual memory consumed by the program
Man:the Total amount of virtual memory used by the task. It includes all code, data and shared
Libraries plus pages that has been swapped out and pages that has been mapped but not used.
Res: Memory usage resident memory, which is what the program really occupies
Man:the non-swapped Physical Memory a task has used
SHR: Shared memory, shared library What's
Mans: The amount of shared memory used by a task. It simply reflects memory that could be potentially
shared with other processes
Data: The memory occupied by the database, in addition to the executable file memory.
Mans: The amount of virtual memory devoted to other than executable code, also known as the ' data resi‐
Dent set ' size or DRS.
Swap: Swap out the space that has been applied but not used
Man:memory that was not resident but was present in a task. This was memory that had been swapped out
But could include additional non-resident memory. This column was calculated by subtracting phys‐
ical memory from virtual memory
.
Here are some examples to illustrate:
#include <stdio.h>#include<stdlib.h>intMain () {Chararr[1024x768*1024x768*1]; void* p = malloc (1024x768*1024x768* + ); if(NULL = = p) {printf ("malloc mem fail.");return; } Sleep ( $);}
GCC Malloc.c-o malloc
Operation Result:
From above you can see the data: the sum of heaps and stacks.
Can you tell from man's manual that virt = 4+513m + 228?
Continue the experiment:
intMain () {Chararr[1024x768*1024x768*1]; void* p = malloc (1024x768*1024x768* + ); if(NULL = = p) {printf ("malloc mem fail.");return; } Memset (P,0,1024x768*1024x768* +) ; memset (arr,0,1024x768*1024x768*1) ; Sleep ( $);}
Operation Result:
As can be seen from the results
The memory space that the RES process is using, after requesting memory and using
Continue below:
#include <stdio.h>#include<stdlib.h>#include<string.h>#include<sys/ipc.h>#include<sys/shm.h>intMain () {Chararr[1024x768*1024x768*1]; void* p = malloc (1024x768*1024x768* + ); if(NULL = = p) {printf ("malloc mem fail.");return; } intFD = Shmget (Ipc_private,1024x768*1024x768* -,0666|ipc_creat); if( -1= = FD) {return; } void* Pshm = Shmat (FD, NULL,0); Memset (P,0,1024x768*1024x768* +) ; memset (arr,0,1024x768*1024x768*1) ; memset (PSHM,2,1024x768*1024x768* -/2); Sleep ( $);}
Operation Result:
As can be seen from the above
SHR: The space used for shared memory.
Swap: Memory stack shared memory that has been applied but not used
To summarize:
Virt: Virtual memory, containing code snippets, stacks.
Res: The memory the process really uses
Swap: The memory that has been applied but not used
Data: Heap + stack
SHR: The space used for shared memory.