pmap 命令用于显示一个或多个进程的内存状态
 
介绍 pmap能更详细的查看进程内存映射情况。
pmap命令输出的内容来自于/proc/{pid}/maps和/proc/{pid}/smaps这两个文件,第一个文件包含了每段的一个大概描述,而后一个文件包含了更详细的信息。
选项 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Usage: pmap [options] pid [pid ...] Options:  -x, --extended       show details  显示扩展格式  -X             show even more details       WARNING: format changes according to /proc/PID/smaps  -XX             show everything the kernel provides  -c, --read-rc        read the default rc  -C, --read-rc-from=<file>  read the rc from file  -n, --create-rc       create new default rc  -N, --create-rc-to=<file>  create new rc to file       NOTE: pid arguments are not allowed with -n, -N  -d, --device        show the device format  显示设备格式  -q, --quiet         do not display header and footer  -p, --show-path       show path in the mapping  -A, --range=<low>[,<high>] limit results to the given range  -h, --help   display this help and exit -V, --version output version information and exit For more details see pmap(1). 
 
扩展和设备格式 Address: 映像起始地址 Kbytes: 映像大小 RSS: 驻留集大小 Dirty: 脏页大小 Mode: permissions on map 映像权限: r=read, w=write, x=execute, s=shared, p=private (copy on write) Mapping: 映像支持文件;[anon]为已分配内存,可以理解为匿名块;[stack]为程序堆栈 Offset: 文件偏移 Device: 设备名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [root@C44 ~]# pmap -d 1 1:  init [5]           Address  Kbytes Mode Offset      Device  Mapping 00934000   88 r-x-- 0000000000000000 008:00005 ld-2.3.4.so 0094a000    4 r---- 0000000000015000 008:00005 ld-2.3.4.so 0094b000    4 rw--- 0000000000016000 008:00005 ld-2.3.4.so 0094e000  1188 r-x-- 0000000000000000 008:00005 libc-2.3.4.so 00a77000    8 r---- 0000000000129000 008:00005 libc-2.3.4.so 00a79000    8 rw--- 000000000012b000 008:00005 libc-2.3.4.so 00a7b000    8 rw--- 0000000000a7b000 000:00000  [ anon ] 00a85000   52 r-x-- 0000000000000000 008:00005 libsepol.so.1 00a92000    4 rw--- 000000000000c000 008:00005 libsepol.so.1 00a93000   32 rw--- 0000000000a93000 000:00000  [ anon ] 00d9d000   52 r-x-- 0000000000000000 008:00005 libselinux.so.1 00daa000    4 rw--- 000000000000d000 008:00005 libselinux.so.1 08048000   28 r-x-- 0000000000000000 008:00005 init 0804f000    4 rw--- 0000000000007000 008:00005 init 084e1000   132 rw--- 00000000084e1000 000:00000  [ anon ] b7f5d000    8 rw--- 00000000b7f5d000 000:00000  [ anon ] bffee000   72 rw--- 00000000bffee000 000:00000  [ stack ] ffffe000    4 ----- 0000000000000000 000:00000  [ anon ] mapped: 1700K  writeable/private: 276K  shared: 0K 
 
最后一行的值
mapped 表示该进程映射的虚拟地址空间大小,也就是该进程预先分配的虚拟内存大小,即ps出的vsz
writeable/private  表示进程所占用的私有地址空间大小,也就是该进程实际使用的内存大小
shared 表示进程和其他进程共享的内存大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [root@info ~]# pmap -x 1013 1013: /usr/sbin/sshd Address Kbytes RSS Dirty Mode Mapping 00110000 1480 92 0 r-x- libcrypto.so.1.0.0 00282000 80 80 80 rw-- libcrypto.so.1.0.0 00296000 12 8 4 rw-- [ anon ] 00299000 36 0 0 r-x- libkrb5support.so.0.1 002a2000 4 4 4 rw-- libkrb5support.so.0.1 002a3000 16 0 0 r-x- libplc4.so 002a7000 4 4 4 rw-- libplc4.so 002ab000 88 4 0 r-x- libaudit.so.1.0.0 002c1000 4 4 4 r--- libaudit.so.1.0.0 002c2000 4 4 4 rw-- libaudit.so.1.0.0 002c3000 216 4 0 r-x- libgssapi_krb5.so.2.2 002f9000 4 4 4 rw-- libgssapi_krb5.so.2.2 002fa000 808 4 0 r-x- libkrb5.so.3.3 003c4000 24 24 24 rw-- libkrb5.so.3.3 003ca000 152 4 0 r-x- libk5crypto.so.3.1 003f0000 4 4 4 rw-- libk5crypto.so.3.1 003f1000 92 0 0 r-x- libnssutil3.so 00408000 12 12 12 rw-- libnssutil3.so 0040b000 12 0 0 r-x- libplds4.so 0040e000 4 4 4 rw-- libplds4.so   --- --- --- --- --- total kB 8232 - - - 
 
扩展 /proc/pid/smaps各字段含义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 01785000-017a6000 rw-p 00000000 00:00 0                                  [heap] Size:                132 kB Rss:                  12 kB Pss:                  12 kB Shared_Clean:          0 kB Shared_Dirty:          0 kB Private_Clean:         0 kB Private_Dirty:        12 kB Referenced:           12 kB Anonymous:            12 kB AnonHugePages:         0 kB Swap:                  0 kB KernelPageSize:        4 kB MMUPageSize:           4 kB 
 
见linux /proc/pid/smaps各字段含义 
 
参考链接