如题,步骤如下
1)ps命令查看某进程的PID
2)通过/proc文件系统查看
- 方法一
查看/proc/[pid]/statm内存使用情况,以页为单位,每页4KB。每列含义分别为:虚拟内存、物理内存、共享内存、 文本、库、数据、脏页。
$ cat /proc/3092/statm
1296 470 432 2 0 131 0
上述结果表示PID=3092的进程,虚拟内存=1296*4KB=5184KB,物理内存=470*4KB=1880KB。
- 方法二
查看/proc/[pid]/status节点更容易解析的格式。
示例如下,可知PID=3092的进程,虚拟内存=VmSize=5184KB,物理内存=VmRss=1880KB。
$ cat /proc/3092/status
Name: main
Umask: 0002
State: S (sleeping)
Tgid: 3092
Ngid: 0
Pid: 3092
PPid: 1514
TracerPid: 0
Uid: 1000 1000 1000 1000
Gid: 1000 1000 1000 1000
FDSize: 256
Groups: 4 24 27 30 46 120 131 132 1000
NStgid: 3092
NSpid: 3092
NSpgid: 3092
NSsid: 1514
VmPeak: 5184 kB
VmSize: 5184 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 1880 kB
VmRSS: 1880 kB
RssAnon: 152 kB
RssFile: 1728 kB
RssShmem: 0 kB
VmData: 392 kB
VmStk: 132 kB
VmExe: 8 kB
VmLib: 3104 kB
VmPTE: 44 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
CoreDumping: 0
THP_enabled: 1
Threads: 1
SigQ: 0/7101
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000180000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 000001ffffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Seccomp_filters: 0
Speculation_Store_Bypass: thread vulnerable
SpeculationIndirectBranch: conditional enabled
Cpus_allowed: ffffffff,ffffffff,ffffffff,ffffffff
Cpus_allowed_list: 0-127
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 6
nonvoluntary_ctxt_switches: 45
关于/proc/[pid]/statm和/proc/[pid]/status的更多信息,可在Linux系统中命令行键入man proc查看。