Centos uses the ps command to view the memory of the process

Source: Internet
Author: User
Using the ps command to view the process memory ps command is a common program in Linux to view the process status. it has several fields that can be used to view the process memory usage: sz, rss, vsz. Note: sz: the number of physical pages occupied by the process image is the virtual memory size expressed in units of physical pages; rss: the physical memory size occupied by the process, the unit is kB; vsz: the virtual memory size of the process, in kB. it is equal to the size of the sz multiplied by the physical page (usually 4 kB on the x86 platform ). Run the ps command to view the memory of the process.
The ps command is a common program in Linux to view the process status. it has several fields to view the process memory usage: sz, rss, and vsz. They are described as follows:
Sz: the number of physical pages occupied by process images, which is the virtual memory size expressed in the unit of physical pages;
Rss: the size of the physical memory occupied by the process, in kB;
Vsz: the virtual memory size of a process, in kB. it is equal to the size of sz multiplied by the physical page (usually 4 kB on the x86 platform ).
If I want to view the memory usage of program a. out, the operation is as follows:
$./A. out &
[1] 10069
$ Ps-O sz, rsz, vsz
PID SZ RSS VSZ S TTY TIME COMMAND
6793 1545 3648 6180 S pts/2 00:00:00/bin/bash
10069 404 304 1616 S pts/2 00:00:00./a. out
10070 626 876 2504 R pts/2 00:00:00 ps-O sz, rss, vsz
The output line 3rd of the ps command above is related to./a. out. We can see that the virtual memory size is 1616kB, and the physical memory occupied currently is 304kB (other data on the disk or swap partition). The virtual pseudo memory occupies 404 physical pages. Because the physical page size of my machine is 4 kB, we can verify that 404x4 kB is equal to 16 kB.
Use the/proc file system to view the memory usage of the process
The output of ps commands is not very detailed about the memory. in particular, a large part of the memory used by the process is used by shared library functions, therefore, the output of the ps command does not see how much memory the process uses. To view more detailed information, you can use the/proc file system. This file system exists on the disk, but can be operated like other common files. It is an interface provided by Linux for users to view process information. Two files in/proc are related to the process memory:/proc/ /Status and/proc/ /Smaps.
Through/proc/ /Status can be used to view the memory usage of processes, including VmSize, physical memory (VmRSS), Data Segment size (VmData), and stack size (VmStk ), the size of the code segment (VmExe), the size of the shared library code segment (VmLib), and so on.
$ Cat/proc/10069/status
Name: a. out
State: S (sleeping)
Tgid: 10069
Pid: 10069
PPid: 6793
TracerPid: 0
Uid: 1001 1001 1001 1001
Gid: 1001 1001 1001 1001
FDSize: 256.
Groups: 1000 1001
VmPeak: 1692 kB
VmSize: 1616 kB
VmLck: 0 kB
VmHWM: 304 kB
VmRSS: 304 kB
VmData: 28 kB
VmStk: 88 kB
VmExe: 4 kB
VmLib: 1464 kB
VmPTE: 20 kB
Threads: 1
SigQ: 0/16382
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000000000
CapInh: 0000000000000000
Cappr: 0000000000000000
CapEff: 0000000000000000
CapBnd: ffffffffffffff
Cpus_allowed: f
Cpus_allowed_list: 0-3
Mems_allowed: 1
Mems_allowed_list: 0
Voluntary_ctxt_switches: 1
Nonvoluntary_ctxt_switches: 1
Note that the sum of VmData, VmStk, VmExe, and VmLib is not equal to VmSize. This is because the data segment of the shared library function is not included (VmData only contains the data segment of the. out program, not the data segment of the shared library function, or the region mapped through mmap. VmLib only contains the code segment of the shared library, not the data segment of the shared library ).
Through/proc/ /Smaps can view the ING of the entire virtual address space of the process. its output is from the low address to the high address, and relevant information of each ing area is output in sequence, as shown below:
$ Cat/proc/10069/smaps
00110000-00263000 r-xp 00000000/lib/tls/i686/cmov/libc-2.11.1.so
Size: 1356 kB
Rss: 148 kB
Pss: 8 kB
Shared_Clean: 148 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 0 kB
References: 148 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
......
......
Bfd7f000-bfd94000 rw-p 00000000 0 [stack]
Size: 88 kB
Rss: 8 kB
Pss: 8 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 8 kB
Referenced: 8 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Note: in rwxp, p indicates private ing (using Copy-On-Write technology ). The Size field is the Size of the region.
References
Ps (1)-O option.
Proc (5)/proc/[pid]/status and/proc/[pid]/smaps entries.

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.