linux下使用pmap和ldd查看进程调用了什么lib

在写安装脚本或者其他时候我们想了解某个经常调用了哪些lib,我们可以使用pmap方法,显示出的lib比较全面,当然也可以使用ldd来查看。接下来看看linux下使用pmap和ldd的命令。

pmap命令

使用方法:pmap 进程pid

如下是查看sshd调用了哪些lib

[root@localhost ~]# ps -ef|grep sshd
root       1588      1  0 16:05 ?        00:00:00 /usr/sbin/sshd
root       1972   1588  0 16:07 ?        00:00:00 sshd: root@pts/0 
root       2078   1974  0 16:37 pts/0    00:00:00 grep sshd
[root@localhost ~]# pmap 1588
1588:   /usr/sbin/sshd
00007fc5b5aa1000     52K r-x--  /lib64/libnss_files-2.12.so
00007fc5b5aae000   2044K -----  /lib64/libnss_files-2.12.so
00007fc5b5cad000      4K r----  /lib64/libnss_files-2.12.so
00007fc5b5cae000      4K rw---  /lib64/libnss_files-2.12.so
00007fc5b5caf000     28K r-x--  /lib64/librt-2.12.so
00007fc5b5cb6000   2044K -----  /lib64/librt-2.12.so
00007fc5b5eb5000      4K r----  /lib64/librt-2.12.so
00007fc5b5eb6000      4K rw---  /lib64/librt-2.12.so
00007fc5b5eb7000    228K r-x--  /lib64/libnspr4.so
00007fc5b5ef0000   2048K -----  /lib64/libnspr4.so
00007fc5b60f0000      4K r----  /lib64/libnspr4.so
00007fc5b60f1000      8K rw---  /lib64/libnspr4.so
00007fc5b60f3000      8K rw---    [ anon ]
00007fc5b60f5000     12K r-x--  /lib64/libplds4.so
00007fc5b60f8000   2044K -----  /lib64/libplds4.so
00007fc5b62f7000      4K r----  /lib64/libplds4.so
00007fc5b62f8000      4K rw---  /lib64/libplds4.so
00007fc5b62f9000     16K r-x--  /lib64/libplc4.so
00007fc5b62fd000   2044K -----  /lib64/libplc4.so
00007fc5b64fc000      4K r----  /lib64/libplc4.so
00007fc5b64fd000      4K rw---  /lib64/libplc4.so
00007fc5b64fe000    152K r-x--  /usr/lib64/libnssutil3.so
00007fc5b6524000   2044K -----  /usr/lib64/libnssutil3.so
00007fc5b6723000     24K r----  /usr/lib64/libnssutil3.so
00007fc5b6729000      4K rw---  /usr/lib64/libnssutil3.so
00007fc5b672a000     92K r-x--  /lib64/libpthread-2.12.so
00007fc5b6741000   2048K -----  /lib64/libpthread-2.12.so
00007fc5b6941000      4K r----  /lib64/libpthread-2.12.so
00007fc5b6942000      4K rw---  /lib64/libpthread-2.12.so
00007fc5b6943000     16K rw---    [ anon ]
00007fc5b6947000      8K r-x--  /lib64/libkeyutils.so.1.3
00007fc5b6949000   2044K -----  /lib64/libkeyutils.so.1.3
00007fc5b6b48000      4K r----  /lib64/libkeyutils.so.1.3
00007fc5b6b49000      4K rw---  /lib64/libkeyutils.so.1.3
00007fc5b6b4a000     40K r-x--  /lib64/libkrb5support.so.0.1
00007fc5b6b54000   2044K -----  /lib64/libkrb5support.so.0.1
00007fc5b6d53000      4K r----  /lib64/libkrb5support.so.0.1
00007fc5b6d54000      4K rw---  /lib64/libkrb5support.so.0.1
00007fc5b6d55000      8K r-x--  /lib64/libfreebl3.so
00007fc5b6d57000   2044K -----  /lib64/libfreebl3.so
00007fc5b6f56000      4K r----  /lib64/libfreebl3.so
00007fc5b6f57000      4K rw---  /lib64/libfreebl3.so
00007fc5b6f58000   1576K r-x--  /lib64/libc-2.12.so
00007fc5b70e2000   2048K -----  /lib64/libc-2.12.so
00007fc5b72e2000     16K r----  /lib64/libc-2.12.so
00007fc5b72e6000      8K rw---  /lib64/libc-2.12.so
00007fc5b72e8000     16K rw---    [ anon ]
00007fc5b72ec000   1244K r-x--  /usr/lib64/libnss3.so
00007fc5b7423000   2048K -----  /usr/lib64/libnss3.so
00007fc5b7623000     20K r----  /usr/lib64/libnss3.so
00007fc5b7628000      8K rw---  /usr/lib64/libnss3.so
00007fc5b762a000      8K rw---    [ anon ]
00007fc5b762c000     12K r-x--  /lib64/libcom_err.so.2.1
00007fc5b762f000   2044K -----  /lib64/libcom_err.so.2.1
00007fc5b782e000      4K r----  /lib64/libcom_err.so.2.1
00007fc5b782f000      4K rw---  /lib64/libcom_err.so.2.1
00007fc5b7830000    164K r-x--  /lib64/libk5crypto.so.3.1
00007fc5b7859000   2048K -----  /lib64/libk5crypto.so.3.1
00007fc5b7a59000      4K r----  /lib64/libk5crypto.so.3.1
00007fc5b7a5a000      4K rw---  /lib64/libk5crypto.so.3.1
00007fc5b7a5b000      4K rw---    [ anon ]
00007fc5b7a5c000    880K r-x--  /lib64/libkrb5.so.3.3
00007fc5b7b38000   2044K -----  /lib64/libkrb5.so.3.3
00007fc5b7d37000     40K r----  /lib64/libkrb5.so.3.3
00007fc5b7d41000      8K rw---  /lib64/libkrb5.so.3.3
00007fc5b7d43000    260K r-x--  /lib64/libgssapi_krb5.so.2.2
00007fc5b7d84000   2048K -----  /lib64/libgssapi_krb5.so.2.2
00007fc5b7f84000      4K r----  /lib64/libgssapi_krb5.so.2.2
00007fc5b7f85000      8K rw---  /lib64/libgssapi_krb5.so.2.2
00007fc5b7f87000     88K r-x--  /lib64/libresolv-2.12.so
00007fc5b7f9d000   2048K -----  /lib64/libresolv-2.12.so
00007fc5b819d000      4K r----  /lib64/libresolv-2.12.so
00007fc5b819e000      4K rw---  /lib64/libresolv-2.12.so
00007fc5b819f000      8K rw---    [ anon ]
00007fc5b81a1000     28K r-x--  /lib64/libcrypt-2.12.so
00007fc5b81a8000   2048K -----  /lib64/libcrypt-2.12.so
00007fc5b83a8000      4K r----  /lib64/libcrypt-2.12.so
00007fc5b83a9000      4K rw---  /lib64/libcrypt-2.12.so
00007fc5b83aa000    184K rw---    [ anon ]
00007fc5b83d8000     88K r-x--  /lib64/libnsl-2.12.so
00007fc5b83ee000   2044K -----  /lib64/libnsl-2.12.so
00007fc5b85ed000      4K r----  /lib64/libnsl-2.12.so
00007fc5b85ee000      4K rw---  /lib64/libnsl-2.12.so
00007fc5b85ef000      8K rw---    [ anon ]
00007fc5b85f1000     84K r-x--  /lib64/libz.so.1.2.3
00007fc5b8606000   2044K -----  /lib64/libz.so.1.2.3
00007fc5b8805000      4K r----  /lib64/libz.so.1.2.3
00007fc5b8806000      4K rw---  /lib64/libz.so.1.2.3
00007fc5b8807000      8K r-x--  /lib64/libutil-2.12.so
00007fc5b8809000   2044K -----  /lib64/libutil-2.12.so
00007fc5b8a08000      4K r----  /lib64/libutil-2.12.so
00007fc5b8a09000      4K rw---  /lib64/libutil-2.12.so
00007fc5b8a0a000   1768K r-x--  /usr/lib64/libcrypto.so.1.0.1e
00007fc5b8bc4000   2048K -----  /usr/lib64/libcrypto.so.1.0.1e
00007fc5b8dc4000    108K r----  /usr/lib64/libcrypto.so.1.0.1e
00007fc5b8ddf000     48K rw---  /usr/lib64/libcrypto.so.1.0.1e
00007fc5b8deb000     16K rw---    [ anon ]
00007fc5b8def000    116K r-x--  /lib64/libselinux.so.1
00007fc5b8e0c000   2044K -----  /lib64/libselinux.so.1
00007fc5b900b000      4K r----  /lib64/libselinux.so.1
00007fc5b900c000      4K rw---  /lib64/libselinux.so.1
00007fc5b900d000      4K rw---    [ anon ]
00007fc5b900e000      8K r-x--  /lib64/libdl-2.12.so
00007fc5b9010000   2048K -----  /lib64/libdl-2.12.so
00007fc5b9210000      4K r----  /lib64/libdl-2.12.so
00007fc5b9211000      4K rw---  /lib64/libdl-2.12.so
00007fc5b9212000     48K r-x--  /lib64/libpam.so.0.82.2
00007fc5b921e000   2048K -----  /lib64/libpam.so.0.82.2
00007fc5b941e000      4K r----  /lib64/libpam.so.0.82.2
00007fc5b941f000      4K rw---  /lib64/libpam.so.0.82.2
00007fc5b9420000     96K r-x--  /lib64/libaudit.so.1.0.0
00007fc5b9438000   2044K -----  /lib64/libaudit.so.1.0.0
00007fc5b9637000      8K r----  /lib64/libaudit.so.1.0.0
00007fc5b9639000     44K rw---  /lib64/libaudit.so.1.0.0
00007fc5b9644000     32K r-x--  /lib64/libwrap.so.0.7.6
00007fc5b964c000   2048K -----  /lib64/libwrap.so.0.7.6
00007fc5b984c000      4K r----  /lib64/libwrap.so.0.7.6
00007fc5b984d000      4K rw---  /lib64/libwrap.so.0.7.6
00007fc5b984e000      4K rw---    [ anon ]
00007fc5b984f000      8K r-x--  /lib64/libfipscheck.so.1.1.0
00007fc5b9851000   2044K -----  /lib64/libfipscheck.so.1.1.0
00007fc5b9a50000      4K r----  /lib64/libfipscheck.so.1.1.0
00007fc5b9a51000      4K rw---  /lib64/libfipscheck.so.1.1.0
00007fc5b9a52000    128K r-x--  /lib64/ld-2.12.so
00007fc5b9c55000     56K rw---    [ anon ]
00007fc5b9c71000      4K rw---    [ anon ]
00007fc5b9c72000      4K r----  /lib64/ld-2.12.so
00007fc5b9c73000      4K rw---  /lib64/ld-2.12.so
00007fc5b9c74000      4K rw---    [ anon ]
00007fc5b9c75000    544K r-x--  /usr/sbin/sshd
00007fc5b9efc000     12K r----  /usr/sbin/sshd
00007fc5b9eff000      4K rw---  /usr/sbin/sshd
00007fc5b9f00000     36K rw---    [ anon ]
00007fc5bb921000    132K rw---    [ anon ]
00007ffd9c561000     84K rw---    [ stack ]
00007ffd9c580000      4K r-x--    [ anon ]
ffffffffff600000      4K r-x--    [ anon ]
 total            66240K

内容非常详细详细,接下来看看ldd命令

ldd命令

使用方法:ldd 程序命令

例如,查看sshd启动需要使用哪些lib,如下:

[root@localhost ~]# ldd /usr/sbin/sshd
        linux-vdso.so.1 =>  (0x00007ffdb9f8d000)
        libfipscheck.so.1 => /lib64/libfipscheck.so.1 (0x00007f7f23c90000)
        libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f7f23a85000)
        libaudit.so.1 => /lib64/libaudit.so.1 (0x00007f7f23860000)
        libpam.so.0 => /lib64/libpam.so.0 (0x00007f7f23652000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f7f2344e000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f7f2322e000)
        libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f7f22e49000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007f7f22c46000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f7f22a2f000)
        libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f7f22816000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f7f225df000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f7f223c4000)
        libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f7f22180000)
        libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f7f21e99000)
        libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f7f21c6c000)
        libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f7f21a68000)
        libnss3.so => /usr/lib64/libnss3.so (0x00007f7f21728000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f7f21393000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003821000000)
        libfreebl3.so => /lib64/libfreebl3.so (0x00007f7f21190000)
        libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f7f20f84000)
        libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f7f20d81000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7f20b64000)
        libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f7f20937000)
        libplc4.so => /lib64/libplc4.so (0x00007f7f20732000)
        libplds4.so => /lib64/libplds4.so (0x00007f7f2052e000)
        libnspr4.so => /lib64/libnspr4.so (0x00007f7f202ef000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f7f200e7000)

ldd将调用到的lib名称以及他的绝对路径给显示出来了,比pmap要直观。

在linux下,不管你使用ldd还是pmap都是可以查看到程序调用的路径。如果查看一个已经运行种但是又不知道程序路径的程序,使用pmap更快捷,对于其他的可以使用ldd,工作种,用得最多的还是ldd.

转载:http://www.ttlsa.com/html/3224.html

发表新评论