linux下使用pmap和ldd查看进程调用了什么lib
在写安装脚本或者其他时候我们想了解某个经常调用了哪些lib,我们可以使用pmap方法,显示出的lib比较全面,当然也可以使用ldd来查看。接下来看看linux下使用pmap和ldd的命令。
pmap命令
使用方法:pmap 进程pid
如下是查看nginx调用了哪些lib
# pmap 2492 2492: nginx: master process /usr/local/nginx-1.4.1/sbin/nginx 0000000000400000 8408K r-x-- /usr/local/nginx-1.4.1/sbin/nginx 0000000000e35000 332K rw--- /usr/local/nginx-1.4.1/sbin/nginx 0000000000e88000 632K rw--- [ anon ] 0000000001643000 1356K rw--- [ anon ] 00000032df200000 176K r-x-- /lib64/libpcre.so.0.0.1 00000032df22c000 2044K ----- /lib64/libpcre.so.0.0.1 00000032df42b000 4K rw--- /lib64/libpcre.so.0.0.1 000000341b400000 340K r-x-- /usr/lib64/libssl.so.1.0.0 000000341b455000 2048K ----- /usr/lib64/libssl.so.1.0.0 000000341b655000 12K r---- /usr/lib64/libssl.so.1.0.0 000000341b658000 20K rw--- /usr/lib64/libssl.so.1.0.0 000000341b800000 12K r-x-- /lib64/libcom_err.so.2.1 000000341b803000 2044K ----- /lib64/libcom_err.so.2.1 000000341ba02000 4K r---- /lib64/libcom_err.so.2.1 000000341ba03000 4K rw--- /lib64/libcom_err.so.2.1 000000341bc00000 260K r-x-- /lib64/libgssapi_krb5.so.2.2 000000341bc41000 2048K ----- /lib64/libgssapi_krb5.so.2.2 000000341be41000 4K r---- /lib64/libgssapi_krb5.so.2.2 000000341be42000 8K rw--- /lib64/libgssapi_krb5.so.2.2 000000341c000000 876K r-x-- /lib64/libkrb5.so.3.3 000000341c0db000 2044K ----- /lib64/libkrb5.so.3.3 000000341c2da000 40K r---- /lib64/libkrb5.so.3.3 000000341c2e4000 8K rw--- /lib64/libkrb5.so.3.3 000000341cc00000 88K r-x-- /lib64/libgcc_s-4.4.7-20120601.so.1 000000341cc16000 2044K ----- /lib64/libgcc_s-4.4.7-20120601.so.1 000000341ce15000 4K rw--- /lib64/libgcc_s-4.4.7-20120601.so.1 000000353aa00000 68K r-x-- /usr/lib64/libXpm.so.4.11.0 000000353aa11000 2044K ----- /usr/lib64/libXpm.so.4.11.0 000000353ac10000 4K rw--- /usr/lib64/libXpm.so.4.11.0 000000358f800000 128K r-x-- /lib64/ld-2.12.so 000000358fa1f000 4K r---- /lib64/ld-2.12.so 000000358fa20000 4K rw--- /lib64/ld-2.12.so 000000358fa21000 4K rw--- [ anon ] 000000358fc00000 1576K r-x-- /lib64/libc-2.12.so 000000358fd8a000 2044K ----- /lib64/libc-2.12.so 000000358ff89000 16K r---- /lib64/libc-2.12.so 000000358ff8d000 4K rw--- /lib64/libc-2.12.so 000000358ff8e000 20K rw--- [ anon ] 0000003590000000 8K r-x-- /lib64/libdl-2.12.so 0000003590002000 2048K ----- /lib64/libdl-2.12.so 0000003590202000 4K r---- /lib64/libdl-2.12.so 0000003590203000 4K rw--- /lib64/libdl-2.12.so 0000003590400000 92K r-x-- /lib64/libpthread-2.12.so 0000003590417000 2048K ----- /lib64/libpthread-2.12.so 0000003590617000 4K r---- /lib64/libpthread-2.12.so 0000003590618000 4K rw--- /lib64/libpthread-2.12.so 0000003590619000 16K rw--- [ anon ] 0000003590c00000 84K r-x-- /lib64/libz.so.1.2.3 0000003590c15000 2044K ----- /lib64/libz.so.1.2.3 0000003590e14000 4K r---- /lib64/libz.so.1.2.3 0000003590e15000 4K rw--- /lib64/libz.so.1.2.3 0000003591000000 116K r-x-- /lib64/libselinux.so.1 000000359101d000 2044K ----- /lib64/libselinux.so.1 000000359121c000 4K r---- /lib64/libselinux.so.1 000000359121d000 4K rw--- /lib64/libselinux.so.1 000000359121e000 4K rw--- [ anon ] 0000003591400000 28K r-x-- /lib64/librt-2.12.so 0000003591407000 2044K ----- /lib64/librt-2.12.so 0000003591606000 4K r---- /lib64/librt-2.12.so 0000003591607000 4K rw--- /lib64/librt-2.12.so 0000003591c00000 88K r-x-- /lib64/libresolv-2.12.so 0000003591c16000 2048K ----- /lib64/libresolv-2.12.so 0000003591e16000 4K r---- /lib64/libresolv-2.12.so 0000003591e17000 4K rw--- /lib64/libresolv-2.12.so 0000003591e18000 8K rw--- [ anon ] 0000003592000000 28K r-x-- /lib64/libcrypt-2.12.so 0000003592007000 2048K ----- /lib64/libcrypt-2.12.so 0000003592207000 4K r---- /lib64/libcrypt-2.12.so 0000003592208000 4K rw--- /lib64/libcrypt-2.12.so 0000003592209000 184K rw--- [ anon ] 0000003592400000 372K r-x-- /lib64/libfreebl3.so 000000359245d000 2044K ----- /lib64/libfreebl3.so 000000359265c000 4K r---- /lib64/libfreebl3.so 000000359265d000 4K rw--- /lib64/libfreebl3.so 000000359265e000 16K rw--- [ anon ] 0000003593000000 164K r-x-- /lib64/libk5crypto.so.3.1 0000003593029000 2048K ----- /lib64/libk5crypto.so.3.1 0000003593229000 4K r---- /lib64/libk5crypto.so.3.1 000000359322a000 4K rw--- /lib64/libk5crypto.so.3.1 000000359322b000 4K rw--- [ anon ] 0000003593800000 1488K r-x-- /usr/lib64/libcrypto.so.1.0.0 0000003593974000 2044K ----- /usr/lib64/libcrypto.so.1.0.0 0000003593b73000 100K r---- /usr/lib64/libcrypto.so.1.0.0 0000003593b8c000 40K rw--- /usr/lib64/libcrypto.so.1.0.0 0000003593b96000 16K rw--- [ anon ] 0000003594c00000 8K r-x-- /lib64/libkeyutils.so.1.3 0000003594c02000 2044K ----- /lib64/libkeyutils.so.1.3 0000003594e01000 4K r---- /lib64/libkeyutils.so.1.3 0000003594e02000 4K rw--- /lib64/libkeyutils.so.1.3 0000003595400000 40K r-x-- /lib64/libkrb5support.so.0.1 000000359540a000 2044K ----- /lib64/libkrb5support.so.0.1 0000003595609000 4K r---- /lib64/libkrb5support.so.0.1 000000359560a000 4K rw--- /lib64/libkrb5support.so.0.1 0000003762400000 524K r-x-- /lib64/libm-2.12.so 0000003762483000 2044K ----- /lib64/libm-2.12.so 0000003762682000 4K r---- /lib64/libm-2.12.so 0000003762683000 4K rw--- /lib64/libm-2.12.so 0000003763400000 608K r-x-- /usr/lib64/libfreetype.so.6.3.22 0000003763498000 2044K ----- /usr/lib64/libfreetype.so.6.3.22 0000003763697000 24K rw--- /usr/lib64/libfreetype.so.6.3.22 0000003763c00000 208K r-x-- /usr/lib64/libfontconfig.so.1.4.4 0000003763c34000 2048K ----- /usr/lib64/libfontconfig.so.1.4.4 0000003763e34000 8K rw--- /usr/lib64/libfontconfig.so.1.4.4 0000003764800000 148K r-x-- /usr/lib64/libpng12.so.0.49.0 0000003764825000 2048K ----- /usr/lib64/libpng12.so.0.49.0 0000003764a25000 4K rw--- /usr/lib64/libpng12.so.0.49.0 0000003766c00000 252K r-x-- /usr/lib64/libjpeg.so.62.0.0 0000003766c3f000 2048K ----- /usr/lib64/libjpeg.so.62.0.0 0000003766e3f000 4K rw--- /usr/lib64/libjpeg.so.62.0.0 0000003766e40000 64K rw--- [ anon ] 0000003769200000 928K r-x-- /usr/lib64/libstdc++.so.6.0.13 00000037692e8000 2048K ----- /usr/lib64/libstdc++.so.6.0.13 00000037694e8000 28K r---- /usr/lib64/libstdc++.so.6.0.13 00000037694ef000 8K rw--- /usr/lib64/libstdc++.so.6.0.13 00000037694f1000 84K rw--- [ anon ] 00000037cc000000 8K r-x-- /usr/lib64/libXau.so.6.0.0 00000037cc002000 2048K ----- /usr/lib64/libXau.so.6.0.0 00000037cc202000 4K rw--- /usr/lib64/libXau.so.6.0.0 00000037cc400000 116K r-x-- /usr/lib64/libxcb.so.1.1.0 00000037cc41d000 2048K ----- /usr/lib64/libxcb.so.1.1.0 00000037cc61d000 4K rw--- /usr/lib64/libxcb.so.1.1.0 00000037cc800000 1244K r-x-- /usr/lib64/libX11.so.6.3.0 00000037cc937000 2048K ----- /usr/lib64/libX11.so.6.3.0 00000037ccb37000 24K rw--- /usr/lib64/libX11.so.6.3.0 0000003dbfe00000 152K r-x-- /lib64/libexpat.so.1.5.2 0000003dbfe26000 2044K ----- /lib64/libexpat.so.1.5.2 0000003dc0025000 12K rw--- /lib64/libexpat.so.1.5.2 00007f19d07e7000 288K rw-s- /dev/zero (deleted) 00007f19d082f000 200K rw-s- /dev/zero (deleted) 00007f19d0861000 48K r-x-- /lib64/libnss_files-2.12.so 00007f19d086d000 2048K ----- /lib64/libnss_files-2.12.so 00007f19d0a6d000 4K r---- /lib64/libnss_files-2.12.so 00007f19d0a6e000 4K rw--- /lib64/libnss_files-2.12.so 00007f19d0a6f000 52K rw--- [ anon ] 00007f19d0a7c000 136K r-x-- /usr/lib64/libgd.so.2.0.0 00007f19d0a9e000 2048K ----- /usr/lib64/libgd.so.2.0.0 00007f19d0c9e000 132K rw--- /usr/lib64/libgd.so.2.0.0 00007f19d0cbf000 28K rw--- [ anon ] 00007f19d0cce000 4K rw-s- /dev/zero (deleted) 00007f19d0ccf000 4K rw--- [ anon ] 00007fffb29c2000 132K rw--- [ stack ] 00007fffb29fe000 8K r-x-- [ anon ] ffffffffff600000 4K r-x-- [ anon ] total 88388K
内容非常详细详细,接下来看看ldd命令
ldd命令
使用方法:ldd 程序命令
例如,查看nginx启动需要使用哪些lib,如下:
# ldd /usr/local/nginx-1.4.1/sbin/nginx linux-vdso.so.1 => (0x00007fff41cf0000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003590400000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003592000000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003769200000) librt.so.1 => /lib64/librt.so.1 (0x0000003591400000) libm.so.6 => /lib64/libm.so.6 (0x0000003762400000) libpcre.so.0 => /lib64/libpcre.so.0 (0x00000032df200000) libssl.so.10 => /usr/lib64/libssl.so.10 (0x000000341b400000) libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003593800000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003590000000) libz.so.1 => /lib64/libz.so.1 (0x0000003590c00000) libgd.so.2 => /usr/lib64/libgd.so.2 (0x00007f6d99201000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000341cc00000) libc.so.6 => /lib64/libc.so.6 (0x000000358fc00000) /lib64/ld-linux-x86-64.so.2 (0x000000358f800000) libfreebl3.so => /lib64/libfreebl3.so (0x0000003592400000) libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x000000341bc00000) libkrb5.so.3 => /lib64/libkrb5.so.3 (0x000000341c000000) libcom_err.so.2 => /lib64/libcom_err.so.2 (0x000000341b800000) libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003593000000) libXpm.so.4 => /usr/lib64/libXpm.so.4 (0x000000353aa00000) libX11.so.6 => /usr/lib64/libX11.so.6 (0x00000037cc800000) libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x0000003766c00000) libfontconfig.so.1 => /usr/lib64/libfontconfig.so.1 (0x0000003763c00000) libfreetype.so.6 => /usr/lib64/libfreetype.so.6 (0x0000003763400000) libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x0000003764800000) libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003595400000) libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003594c00000) libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003591c00000) libxcb.so.1 => /usr/lib64/libxcb.so.1 (0x00000037cc400000) libexpat.so.1 => /lib64/libexpat.so.1 (0x0000003dbfe00000) libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003591000000) libXau.so.6 => /usr/lib64/libXau.so.6 (0x00000037cc000000)
ldd将调用到的lib名称以及他的绝对路径给显示出来了,比pmap要直观。
在linux下,不管你使用ldd还是pmap都是可以查看到程序调用的路径。如果查看一个已经运行种但是又不知道程序路径的程序,使用pmap更快捷,对于其他的可以使用ldd,工作种,用得最多的还是ldd.
转载请著名出处:http://www.ttlsa.com/html/3224.html
本文由主机测评网发布,不代表主机测评网立场,转载联系作者并注明出处:https://zhuji.jb51.net/yunwei/8246.html