00. 目录
文章目录
01. 命令概述
pmap命令用于报告进程的内存映射关系,是Linux调试及运维一个很好的工具。
02. 命令格式
pmap [选项] 进程号 [...]
03. 常用选项
-x:显示扩展格式
-d:显示设备格式
-q:不显示头尾行
-V:显示指定版本
04. 参考示例
扩展格式和设备格式域
Address: start address of map 映像起始地址
Kbytes: size of map in kilobytes 映像大小
RSS: resident set size in kilobytes 驻留集大小
Dirty: dirty pages (both shared and private) in kilobytes 脏页大小
Mode: permissions on map 映像权限: r=read, w=write, x=execute, s=shared, p=private (copy on write)
Mapping: file backing the map , or '[ anon ]' for allocated memory, or '[ stack ]' for the program stack. 映像支持文件,[anon]为已分配内存 [stack]为程序堆栈
Offset: offset into the file 文件偏移
Device: device name (major:minor) 设备名
4.1 查看进程1的设备格式
[root@localhost ~]# pmap -d 1
1: /usr/lib/systemd/systemd --switched-root --system --deserialize 22
Address Kbytes Mode Offset Device Mapping
0000558b9e31a000 1408 r-x-- 0000000000000000 008:00003 systemd
0000558b9e679000 140 r---- 000000000015f000 008:00003 systemd
0000558b9e69c000 4 rw--- 0000000000182000 008:00003 systemd
0000558b9f184000 1292 rw--- 0000000000000000 000:00000 [ anon ]
00007effac000000 164 rw--- 0000000000000000 000:00000 [ anon ]
00007effac029000 65372 ----- 0000000000000000 000:00000 [ anon ]
00007effb4000000 164 rw--- 0000000000000000 000:00000 [ anon ]
00007effb4029000 65372 ----- 0000000000000000 000:00000 [ anon ]
4.2 查看进程1的设备格式,不显示头尾行
[root@localhost ~]# pmap -d -q 1
1: /usr/lib/systemd/systemd --switched-root --system --deserialize 22
0000558b9e31a000 1408 r-x-- 0000000000000000 008:00003 systemd
0000558b9e679000 140 r---- 000000000015f000 008:00003 systemd
0000558b9e69c000 4 rw--- 0000000000182000 008:00003 systemd
0000558b9f184000 1292 rw--- 0000000000000000 000:00000 [ anon ]
00007effac000000 164 rw--- 0000000000000000 000:00000 [ anon ]
00007effac029000 65372 ----- 0000000000000000 000:00000 [ anon ]
00007effb4000000 164 rw--- 0000000000000000 000:00000 [ anon ]
4.3 查看进程1的扩展格式
[root@localhost ~]# pmap -x 1
1: /usr/lib/systemd/systemd --switched-root --system --deserialize 22
Address Kbytes RSS Dirty Mode Mapping
0000558b9e31a000 1408 952 0 r-x-- systemd
0000558b9e679000 140 132 132 r---- systemd
0000558b9e69c000 4 4 4 rw--- systemd
0000558b9f184000 1292 1100 1100 rw--- [ anon ]
00007effac000000 164 12 12 rw--- [ anon ]
00007effac029000 65372 0 0 ----- [ anon ]
4.4 循环显示进程666的设备格式的最后1行,间隔1秒
[root@localhost ~]# while true; do pmap -d 666 |tail -1;sleep 1;done
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K
mapped: 115304K writeable/private: 416K shared: 28K