Linux:pmap命令,查看进程占用的内存及使用地址空间(转)

来源:互联网 发布:天干地支的简便算法 编辑:程序博客网 时间:2024/04/29 00:09

http://www.cnblogs.com/tibetanmastiff/archive/2011/10/10/2205799.html

 

 

情景:

根据apache的工作方式,当我们要判断某个httpd进程使用内存的详细情况的时候,就用到了pmap命令:

 

例如:

1.查看pmap如何使用:

[root@CentOS5 ~]# man pmap

PMAP(1)                       Linux User’s Manual                      PMAP(1)

NAME
       pmap - report memory map of a process

SYNOPSIS
       pmap [ -x | -d ] [ -q ] pids...
       pmap -V

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

GENERAL OPTIONS
       -x   extended       Show the extended format.
       -d   device         Show the device format.
       -q   quiet          Do not display some header/footer lines.
       -V   show version   Displays version of program.

SEE ALSO
       ps(1) pgrep(1)

STANDARDS
       No standards apply, but pmap looks an awful lot like a SunOS command.

AUTHOR
       Albert  Cahalan  <albert@users.sf.net> wrote pmap in 2002, and is the cur-
       rent maintainer of the procps  collection.  Please  send  bug  reports  to
       <procps-feedback@lists.sf.net>.

Linux                          October 26, 2002                        PMAP(1)
(END)


2.参数说明:

       -x   extended       Show the extended format.
       -d   device         Show the device format.
       -q   quiet          Do not display some header/footer lines.
       -V   show version   Displays version of program.

 

3.举例:

查看系统进程:

[root@CentOS5 ~]#ps aux

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          0.0  0.0   2072   616 ?        Ss   May17   0:01 init [3]
(中间部分略)

daemon    9639  0.0  0.1  21164  8484 ?           13:11   0:00 /usr/local/apache2/bin/httpd

(下面部分略)

 

[root@CentOS5 ~]#pmap -d 9639
9639:   /usr/local/apache2/bin/httpd -k start
Address   Kbytes Mode  Offset           Device    Mapping
00110000      28 r-x-- 0000000000000000 008:00003 librt-2.5.so
00117000       4 r---- 0000000000006000 008:00003 librt-2.5.so
00118000       4 rw--- 0000000000007000 008:00003 librt-2.5.so
00119000    1276 r-x-- 0000000000000000 008:00003 libc-2.5.so
00258000       8 r---- 000000000013f000 008:00003 libc-2.5.so
0025a000       4 rw--- 0000000000141000 008:00003 libc-2.5.so
0025b000      12 rw--- 000000000025b000 000:00000   [ anon ]
0025e000      60 r-x-- 0000000000000000 008:00003 libexslt.so.0.8.12
0026d000       4 rw--- 000000000000e000 008:00003 libexslt.so.0.8.12
0026e000     268 r-x-- 0000000000000000 008:00003 libmysqlclient.so.16.0.0
002b1000     168 rw--- 0000000000042000 008:00003 libmysqlclient.so.16.0.0
002db000       4 rw--- 00000000002db000 000:00000   [ anon ]
002dc000     448 r-x-- 0000000000000000 008:00003 libfreetype.so.6.4.0
0034c000      16 rw--- 000000000006f000 008:00003 libfreetype.so.6.4.0
00350000      72 r-x-- 0000000000000000 008:00003 libz.so.1.2.3
00362000       4 rw--- 0000000000011000 008:00003 libz.so.1.2.3
00363000      60 r-x-- 0000000000000000 008:00003 libresolv-2.5.so
00372000       4 r---- 000000000000e000 008:00003 libresolv-2.5.so
00373000       4 rw--- 000000000000f000 008:00003 libresolv-2.5.so
00374000       8 rw--- 0000000000374000 000:00000   [ anon ]
00376000      76 r-x-- 0000000000000000 008:00003 libnsl-2.5.so
00389000       4 r---- 0000000000012000 008:00003 libnsl-2.5.so
0038a000       4 rw--- 0000000000013000 008:00003 libnsl-2.5.so
0038b000       8 rw--- 000000000038b000 000:00000   [ anon ]
0038d000     200 r-x-- 0000000000000000 008:00003 libcurl.so.3.0.0
003bf000       4 rw--- 0000000000031000 008:00003 libcurl.so.3.0.0
003c0000     192 r-x-- 0000000000000000 008:00003 libidn.so.11.5.19
003f0000       4 rw--- 000000000002f000 008:00003 libidn.so.11.5.19
003f1000     188 r-x-- 0000000000000000 008:00003 libxslt.so.1.1.15
00420000       4 rw--- 000000000002f000 008:00003 libxslt.so.1.1.15
00421000     588 r-x-- 0000000000000000 008:00003 libkrb5.so.3.3
004b4000      12 rw--- 0000000000092000 008:00003 libkrb5.so.3.3
004b7000       8 r-x-- 0000000000000000 008:00003 libcom_err.so.2.1
004b9000       4 rw--- 0000000000001000 008:00003 libcom_err.so.2.1
004ba000     148 r-x-- 0000000000000000 008:00003 libk5crypto.so.3.1
004df000       4 rw--- 0000000000025000 008:00003 libk5crypto.so.3.1
004e0000       8 r-x-- 0000000000000000 008:00003 libkeyutils-1.2.so
004e2000       4 rw--- 0000000000001000 008:00003 libkeyutils-1.2.so
004e3000      36 r-x-- 0000000000000000 008:00003 libnss_files-2.5.so
004ec000       4 r---- 0000000000008000 008:00003 libnss_files-2.5.so
004ed000       4 rw--- 0000000000009000 008:00003 libnss_files-2.5.so
004f4000     124 r-x-- 0000000000000000 008:00003 libexpat.so.0.5.0
00513000       8 rw--- 000000000001e000 008:00003 libexpat.so.0.5.0
00517000     180 r-x-- 0000000000000000 008:00003 libgssapi_krb5.so.2.2
00544000       4 rw--- 000000000002d000 008:00003 libgssapi_krb5.so.2.2
00545000      32 r-x-- 0000000000000000 008:00003 libkrb5support.so.0.1
0054d000       4 rw--- 0000000000007000 008:00003 libkrb5support.so.0.1
0054e000      88 r-x-- 0000000000000000 008:00003 libselinux.so.1
00564000       8 rw--- 0000000000015000 008:00003 libselinux.so.1
00566000      44 r-x-- 0000000000000000 008:00003 memcache.so
00571000       4 rw--- 000000000000a000 008:00003 memcache.so
00572000      28 r-x-- 0000000000000000 008:00003 mcrypt.so
00579000       4 rw--- 0000000000007000 008:00003 mcrypt.so
0057a000     156 r-x-- 0000000000000000 008:00003 libmcrypt.so.4.4.8
005a1000      12 rw--- 0000000000027000 008:00003 libmcrypt.so.4.4.8
005a4000      20 rw--- 00000000005a4000 000:00000   [ anon ]
005c9000     120 r-x-- 0000000000000000 008:00003 libjpeg.so.62.0.0
005e7000       4 rw--- 000000000001d000 008:00003 libjpeg.so.62.0.0
00605000      88 r-x-- 0000000000000000 008:00003 mysqli.so
0061b000       8 rw--- 0000000000016000 008:00003 mysqli.so
0068a000     236 r-x-- 0000000000000000 008:00003 libgd.so.2.0.0
006c5000     128 rw--- 000000000003a000 008:00003 libgd.so.2.0.0
006e5000      16 rw--- 00000000006e5000 000:00000   [ anon ]
007bf000     104 r-x-- 0000000000000000 008:00003 ld-2.5.so
007d9000       4 r---- 0000000000019000 008:00003 ld-2.5.so
007da000       4 rw--- 000000000001a000 008:00003 ld-2.5.so
00816000       4 r-x-- 0000000000816000 000:00000   [ anon ]
00817000     988 r-x-- 0000000000000000 008:00003 libxml2.so.2.6.19
0090e000      32 rw--- 00000000000f7000 008:00003 libxml2.so.2.6.19
00916000       4 rw--- 0000000000916000 000:00000   [ anon ]
00929000       8 r-x-- 0000000000000000 008:00003 libdl-2.5.so
0092b000       4 r---- 0000000000001000 008:00003 libdl-2.5.so
0092c000       4 rw--- 0000000000002000 008:00003 libdl-2.5.so
0092f000      76 r-x-- 0000000000000000 008:00003 libpthread-2.5.so
00942000       4 r---- 0000000000013000 008:00003 libpthread-2.5.so
00943000       4 rw--- 0000000000014000 008:00003 libpthread-2.5.so
00944000       8 rw--- 0000000000944000 000:00000   [ anon ]
00948000     148 r-x-- 0000000000000000 008:00003 libm-2.5.so
0096d000       4 r---- 0000000000024000 008:00003 libm-2.5.so
0096e000       4 rw--- 0000000000025000 008:00003 libm-2.5.so
00971000      12 r-x-- 0000000000000000 008:00003 libuuid.so.1.2
00974000       4 rw--- 0000000000003000 008:00003 libuuid.so.1.2
0097b000     152 r-x-- 0000000000000000 008:00003 libapr-1.so.0.4.2
009a1000       4 rw--- 0000000000025000 008:00003 libapr-1.so.0.4.2
009ab000     236 r-x-- 0000000000000000 008:00003 libsepol.so.1
009e6000       4 rw--- 000000000003b000 008:00003 libsepol.so.1
009e7000      40 rw--- 00000000009e7000 000:00000   [ anon ]
00a2f000      20 r-x-- 0000000000000000 008:00003 pdo_mysql.so
00a34000       4 rw--- 0000000000005000 008:00003 pdo_mysql.so
00aa1000      36 r-x-- 0000000000000000 008:00003 libcrypt-2.5.so
00aaa000       4 r---- 0000000000008000 008:00003 libcrypt-2.5.so
00aab000       4 rw--- 0000000000009000 008:00003 libcrypt-2.5.so
00aac000     156 rw--- 0000000000aac000 000:00000   [ anon ]
00b78000     108 r-x-- 0000000000000000 008:00003 libaprutil-1.so.0.3.9
00b93000       4 rw--- 000000000001b000 008:00003 libaprutil-1.so.0.3.9
00b94000    6560 r-x-- 0000000000000000 008:00003 libphp5.so
011fc000     156 rw--- 0000000000667000 008:00003 libphp5.so
01223000      20 rw--- 0000000001223000 000:00000   [ anon ]
03492000     268 r-x-- 0000000000000000 008:00003 libssl.so.0.9.8e
034d5000      16 rw--- 0000000000042000 008:00003 libssl.so.0.9.8e
03c71000      12 r-x-- 0000000000000000 008:00003 libgpg-error.so.0.3.0
03c74000       4 rw--- 0000000000002000 008:00003 libgpg-error.so.0.3.0
03c77000     504 r-x-- 0000000000000000 008:00003 libgcrypt.so.11.5.2
03cf5000      12 rw--- 000000000007d000 008:00003 libgcrypt.so.11.5.2
05748000    1192 r-x-- 0000000000000000 008:00003 libcrypto.so.0.9.8e
05872000      76 rw--- 0000000000129000 008:00003 libcrypto.so.0.9.8e
05885000      16 rw--- 0000000005885000 000:00000   [ anon ]
08048000     484 r-x-- 0000000000000000 008:00003 httpd
080c1000      12 rw--- 0000000000078000 008:00003 httpd
080c4000      12 rw--- 00000000080c4000 000:00000   [ anon ]
0951b000    2136 rw--- 000000000951b000 000:00000   [ anon ]
b7cb2000    2048 r---- 0000000000000000 008:00003 locale-archive (deleted)
b7ee3000      64 rw-s- 0000000000000000 000:00009 zero (deleted)
b7ef3000      12 rw--- 00000000b7ef3000 000:00000   [ anon ]
b7f01000       4 r---- 00000000005da000 008:00003 locale-archive (deleted)
b7f02000       4 rw--- 00000000b7f02000 000:00000   [ anon ]
bfd31000      84 rw--- 00000000bffea000 000:00000   [ stack ]
mapped: 21164K    writeable/private: 3340K    shared: 64K

每列的含义如下:
参数 解释
Address:进程所占的地址空间
Kbytes:该虚拟段的大小
RSS:设备号(主设备:次设备)
Anon:设备的节点号,0表示没有节点与内存相对应
Locked:是否允许swapped
Mode 权限:r=read, w=write, x=execute, s=shared, p=private(copy on write)
Mapping:bash 对应的映像文件名

Resident :表示在内存中驻留的段的空间   
shared :表示这些北分配的内存是被系统中其他进程共享的。    
private :表示只能被该进程使用的空间大小。你可以发现share的空间不具有 private的属性。
Prstat -LP 的输出的意义是:
size:就是该进程占用的地址空间。
RSS:实际被分配的内存的大小。
你看到的resident和RSS不同,是RSS是进程在内存中的实际的大小,这个数值最大可以达到Resident显示数值。

原创粉丝点击