初学者 Linux pmap 命令教程(5 个示例)初学者 Linux pmap 命令教程(5 个示例)初学者 Linux pmap 命令教程(5 个示例)初学者 Linux pmap 命令教程(5 个示例)
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

初学者 Linux pmap 命令教程(5 个示例)

在此页

  1. Linux pmap 命令
  2. Q1。如何使用pmap?
  3. Q2。如何使 pmap 显示扩展输出?
  4. Q3。如何使 pmap 在输出中显示设备格式?
  5. Q4。如何去除页眉和页脚的 pmap 输出?
  6. Q5。如何使 pmap 在输出中显示完整路径?
  7. 结论

Linux 命令行提供了许多工具,可帮助您更多地了解系统中当前处于活动状态的进程。一个这样的实用程序是 pmap,它报告进程内存映射。在本教程中,我们将使用一些易于理解的示例来讨论 pmap 的基础知识。

但在我们这样做之前,值得一提的是,这里的所有示例都已经在 Ubuntu 22.04 LTS 机器上进行了测试。

Linux pmap 命令

Linux 中的 pmap 命令可让您查看一个或多个进程的内存映射。以下是它的语法:

pmap [options] pid [...]

以下是工具手册页对其的解释:

The pmap command reports the memory map of a process or processes.

以下是一些 Q&A 风格的示例,它们可以让您更好地了解 pmap 命令的工作原理。

Q1。如何使用pmap?

基本用法很简单。只需执行不带任何选项的 pmap 命令。当然,您需要传递一个进程 PID 作为输入。

例如,我通过以下方式使用 pmap:

pmap 5146

这是产生的一部分输出:

5146:   gedit
000055bde4835000      8K r-x-- gedit
000055bde4a36000      4K r---- gedit
000055bde4a37000      4K rw--- gedit
000055bde5d32000  13944K rw---   [ anon ]
00007fc910000000    132K rw---   [ anon ]
00007fc910021000  65404K -----   [ anon ]
00007fc918000000    896K rw---   [ anon ]
00007fc9180e0000  64640K -----   [ anon ]
00007fc91c750000    204K r---- UbuntuMono-R.ttf
00007fc91c783000    644K r-x-- libaspell.so.15.2.0
00007fc91c824000   2048K ----- libaspell.so.15.2.0
00007fc91ca24000     20K r---- libaspell.so.15.2.0
00007fc91ca29000      4K rw--- libaspell.so.15.2.0
00007fc91ca2a000      8K r-x-- libenchant_aspell.so
00007fc91ca2c000   2044K ----- libenchant_aspell.so
00007fc91cc2b000      4K r---- libenchant_aspell.so
00007fc91cc2c000      4K rw--- libenchant_aspell.so
00007fc91cc2d000     44K r-x-- libenchant_hspell.so
00007fc91cc38000   2044K ----- libenchant_hspell.so
00007fc91ce37000      4K r---- libenchant_hspell.so
00007fc91ce38000     12K rw--- libenchant_hspell.so
00007fc91ce3b000    428K r-x-- libhunspell-1.6.so.0.0.1
00007fc91cea6000   2044K ----- libhunspell-1.6.so.0.0.1
00007fc91d0a5000      4K r---- libhunspell-1.6.so.0.0.1
00007fc91d0a6000     16K rw--- libhunspell-1.6.so.0.0.1
00007fc91d0aa000     16K r-x-- libenchant_myspell.so
00007fc91d0ae000   2048K ----- libenchant_myspell.so
00007fc91d2ae000      4K r---- libenchant_myspell.so
...
...
...

所以你去吧,输出首先显示进程的名称,然后是内存映射。

Q2。如何使 pmap 显示扩展输出?

要使 pmap 以扩展格式显示输出,请使用 -x 命令行选项。例如:

pmap -x 5146

以下是产生的输出的一部分:

5146:   gedit
Address           Kbytes     RSS   Dirty Mode  Mapping
000055bde4835000       8       4       0 r-x-- gedit
000055bde4835000       0       0       0 r-x-- gedit
000055bde4a36000       4       4       4 r---- gedit
000055bde4a36000       0       0       0 r---- gedit
000055bde4a37000       4       4       4 rw--- gedit
000055bde4a37000       0       0       0 rw--- gedit
000055bde5d32000   13944   13692   13692 rw---   [ anon ]
000055bde5d32000       0       0       0 rw---   [ anon ]
00007fc910000000     132      44      44 rw---   [ anon ]
00007fc910000000       0       0       0 rw---   [ anon ]
00007fc910021000   65404       0       0 -----   [ anon ]
00007fc910021000       0       0       0 -----   [ anon ]
00007fc918000000     896     896     896 rw---   [ anon ]
00007fc918000000       0       0       0 rw---   [ anon ]
00007fc9180e0000   64640       0       0 -----   [ anon ]
00007fc9180e0000       0       0       0 -----   [ anon ]
00007fc91c750000     204     136       0 r---- UbuntuMono-R.ttf
00007fc91c750000       0       0       0 r---- UbuntuMono-R.ttf
00007fc91c783000     644     472       0 r-x-- libaspell.so.15.2.0
00007fc91c783000       0       0       0 r-x-- libaspell.so.15.2.0
00007fc91c824000    2048       0       0 ----- libaspell.so.15.2.0
00007fc91c824000       0       0       0 ----- libaspell.so.15.2.0
00007fc91ca24000      20      20      20 r---- libaspell.so.15.2.0
00007fc91ca24000       0       0       0 r---- libaspell.so.15.2.0
00007fc91ca29000       4       4       4 rw--- libaspell.so.15.2.0
00007fc91ca29000       0       0       0 rw--- libaspell.so.15.2.0
00007fc91ca2a000       8       8       0 r-x-- libenchant_aspell.so
00007fc91ca2a000       0       0       0 r-x-- libenchant_aspell.so
00007fc91ca2c000    2044       0       0 ----- libenchant_aspell.so
00007fc91ca2c000       0       0       0 ----- libenchant_aspell.so
00007fc91cc2b000       4       4       4 r---- libenchant_aspell.so
00007fc91cc2b000       0       0       0 r---- libenchant_aspell.so
...
...
...

请注意,如果您需要更多详细信息,可以使用 -X 命令行选项。

Q3.如何使 pmap 在输出中显示设备格式?

这可以使用 -d 命令行选项来完成。例如:

pmap -d 5146

这是产生的输出的一部分:

5146:   gedit
Address           Kbytes Mode  Offset           Device    Mapping
000055bde4835000       8 r-x-- 0000000000000000 008:00008 gedit
000055bde4a36000       4 r---- 0000000000001000 008:00008 gedit
000055bde4a37000       4 rw--- 0000000000002000 008:00008 gedit
000055bde5d32000   13944 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910000000     132 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910021000   65404 ----- 0000000000000000 000:00000   [ anon ]
00007fc918000000     896 rw--- 0000000000000000 000:00000   [ anon ]
00007fc9180e0000   64640 ----- 0000000000000000 000:00000   [ anon ]
00007fc91c750000     204 r---- 0000000000000000 008:00008 UbuntuMono-R.ttf
00007fc91c783000     644 r-x-- 0000000000000000 008:00008 libaspell.so.15.2.0
00007fc91c824000    2048 ----- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca24000      20 r---- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca29000       4 rw--- 00000000000a6000 008:00008 libaspell.so.15.2.0
00007fc91ca2a000       8 r-x-- 0000000000000000 008:00008 libenchant_aspell.so
00007fc91ca2c000    2044 ----- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2b000       4 r---- 0000000000001000 008:00008 libenchant_aspell.so
00007fc91cc2c000       4 rw--- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2d000      44 r-x-- 0000000000000000 008:00008 libenchant_hspell.so
00007fc91cc38000    2044 ----- 000000000000b000 008:00008 libenchant_hspell.so
00007fc91ce37000       4 r---- 000000000000a000 008:00008 libenchant_hspell.so
00007fc91ce38000      12 rw--- 000000000000b000 008:00008 libenchant_hspell.so
...
...
...

所以你可以看到在输出中添加了一个新的列设备。

Q4.如何去除页眉和页脚的 pmap 输出?

如果您不想在 pmap 输出中看到列名之类的内容,可以使用 -q 命令行选项。

例如:

pmap -q -d 5146

以下是输出:

5146:   gedit
000055bde4835000       8 r-x-- 0000000000000000 008:00008 gedit
000055bde4a36000       4 r---- 0000000000001000 008:00008 gedit
000055bde4a37000       4 rw--- 0000000000002000 008:00008 gedit
000055bde5d32000   13944 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910000000     132 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910021000   65404 ----- 0000000000000000 000:00000   [ anon ]
00007fc918000000     896 rw--- 0000000000000000 000:00000   [ anon ]
00007fc9180e0000   64640 ----- 0000000000000000 000:00000   [ anon ]
00007fc91c750000     204 r---- 0000000000000000 008:00008 UbuntuMono-R.ttf
00007fc91c783000     644 r-x-- 0000000000000000 008:00008 libaspell.so.15.2.0
00007fc91c824000    2048 ----- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca24000      20 r---- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca29000       4 rw--- 00000000000a6000 008:00008 libaspell.so.15.2.0
00007fc91ca2a000       8 r-x-- 0000000000000000 008:00008 libenchant_aspell.so
00007fc91ca2c000    2044 ----- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2b000       4 r---- 0000000000001000 008:00008 libenchant_aspell.so
00007fc91cc2c000       4 rw--- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2d000      44 r-x-- 0000000000000000 008:00008 libenchant_hspell.so
00007fc91cc38000    2044 ----- 000000000000b000 008:00008 libenchant_hspell.so
00007fc91ce37000       4 r---- 000000000000a000 008:00008 libenchant_hspell.so
00007fc91ce38000      12 rw--- 000000000000b000 008:00008 libenchant_hspell.so

所以您可以看到标头已从输出中删除。

Q5.如何使 pmap 在输出中显示完整路径?

如果您希望 pmap 在映射列中显示文件的完整路径,您可以使用 -p 命令行选项。

例如:

pmap -p 5146

这是此命令产生的输出:

5146:   gedit
000055bde4835000      8K r-x-- /usr/bin/gedit
000055bde4a36000      4K r---- /usr/bin/gedit
000055bde4a37000      4K rw--- /usr/bin/gedit
000055bde5d32000  13944K rw---   [ anon ]
00007fc910000000    132K rw---   [ anon ]
00007fc910021000  65404K -----   [ anon ]
00007fc918000000    896K rw---   [ anon ]
00007fc9180e0000  64640K -----   [ anon ]
00007fc91c750000    204K r---- /usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf
00007fc91c783000    644K r-x-- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91c824000   2048K ----- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91ca24000     20K r---- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91ca29000      4K rw--- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91ca2a000      8K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91ca2c000   2044K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91cc2b000      4K r---- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91cc2c000      4K rw--- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91cc2d000     44K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91cc38000   2044K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91ce37000      4K r---- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91ce38000     12K rw--- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91ce3b000    428K r-x-- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91cea6000   2044K ----- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91d0a5000      4K r---- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91d0a6000     16K rw--- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91d0aa000     16K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d0ae000   2048K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d2ae000      4K r---- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d2af000      4K rw--- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d2b0000     44K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_ispell.so
00007fc91d2bb000   2048K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_ispell.so

所以你可以看到在输出中产生了具有完整路径的文件名。

结论

如果您的工作涉及处理进程内存映射,则此工具适合您。在本教程中,我们描述了该命令的基本用法。练习完我们在这里讨论的所有内容后,请前往工具手册页了解更多信息。

©2015-2025 艾丽卡 support@alaica.com