Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check a running process to see what shared libraries it is using?

On Linux, I have a C++ application that is using dlopen() to load some shared libraries, but I'm suspicious that the version of the shared library being loaded is not the one I expect because my debugging trace code does not appear to be executed.

Is there a way to check a running process to query all the shared libraries it currently has open and the path to each of those libraries? In other words, something akin to ldd but that works on a running executable and lists runtime loaded libraries as well.

like image 909
WilliamKF Avatar asked May 09 '13 16:05

WilliamKF


People also ask

How do I view all shared libraries in executables?

We know that a shared library is a library that can be linked to any program at runtime. In order to view all the shared libraries used by an executable we make use of the Linux command utility known as ldd. We can easily locate the shared libraries on a Linux machine, as they usually start with lib* prefix.

How do I view shared library dependencies?

You can use readelf to explore the ELF headers. readelf -d will list the direct dependencies as NEEDED sections. $ readelf -d elfbin Dynamic section at offset 0xe30 contains 22 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libssl. so.

Are shared libraries shared between processes?

Shared code is loaded into memory once in the shared library segment and shared by all processes that reference it. The advantages of shared libraries are: Less disk space is used because the shared library code is not included in the executable programs.

How do I find shared libraries in Linux?

In this standard, folders /lib, /usr/lib and /usr/local/lib are the default folders to store shared libraries. The /lib folder has libraries used during the boot time of the system but also used by programs in the /bin folder. Similarly, the/usr/lib folder has libraries used by programs in the /usr/bin folder.


1 Answers

If you want to know the library files a program have opened, you can try pmap. For example, if we want to know the libraries that bash process 3860 have opened, the result could be:

3860:   bash
08048000    880K r-x--  /bin/bash
08124000      4K r----  /bin/bash
08125000     20K rw---  /bin/bash
0812a000     20K rw---    [ anon ]
099ae000    348K rw---    [ anon ]
b715c000     44K r-x--  /lib/i386-linux-gnu/libnss_files-2.15.so
b7167000      4K r----  /lib/i386-linux-gnu/libnss_files-2.15.so
b7168000      4K rw---  /lib/i386-linux-gnu/libnss_files-2.15.so
b7169000     88K r-x--  /lib/i386-linux-gnu/libnsl-2.15.so
b717f000      4K r----  /lib/i386-linux-gnu/libnsl-2.15.so
b7180000      4K rw---  /lib/i386-linux-gnu/libnsl-2.15.so
b7181000      8K rw---    [ anon ]
b7183000     28K r-x--  /lib/i386-linux-gnu/libnss_compat-2.15.so
b718a000      4K r----  /lib/i386-linux-gnu/libnss_compat-2.15.so
b718b000      4K rw---  /lib/i386-linux-gnu/libnss_compat-2.15.so
b71a1000      4K r----  /usr/lib/locale/locale-archive
b71a2000   1428K r----  /usr/lib/locale/locale-archive
b7307000   2048K r----  /usr/lib/locale/locale-archive
b7507000      4K rw---    [ anon ]
b7508000   1676K r-x--  /lib/i386-linux-gnu/libc-2.15.so
b76ab000      8K r----  /lib/i386-linux-gnu/libc-2.15.so
b76ad000      4K rw---  /lib/i386-linux-gnu/libc-2.15.so
b76ae000     16K rw---    [ anon ]
b76b2000     12K r-x--  /lib/i386-linux-gnu/libdl-2.15.so
b76b5000      4K r----  /lib/i386-linux-gnu/libdl-2.15.so
b76b6000      4K rw---  /lib/i386-linux-gnu/libdl-2.15.so
b76b7000    112K r-x--  /lib/i386-linux-gnu/libtinfo.so.5.9
b76d3000      8K r----  /lib/i386-linux-gnu/libtinfo.so.5.9
b76d5000      4K rw---  /lib/i386-linux-gnu/libtinfo.so.5.9
b76d8000     28K r--s-  /usr/lib/i386-linux-gnu/gconv/gconv-modules.cache
b76df000     40K r-x--  /lib/i386-linux-gnu/libnss_nis-2.15.so
b76e9000      4K r----  /lib/i386-linux-gnu/libnss_nis-2.15.so
b76ea000      4K rw---  /lib/i386-linux-gnu/libnss_nis-2.15.so
b76eb000      8K rw---    [ anon ]
b76ed000      4K r-x--    [ anon ]
b76ee000    128K r-x--  /lib/i386-linux-gnu/ld-2.15.so
b770e000      4K r----  /lib/i386-linux-gnu/ld-2.15.so
b770f000      4K rw---  /lib/i386-linux-gnu/ld-2.15.so
bfbbf000    132K rw---    [ stack ]
 total     7152K

Wish it would be of help for you.

like image 52
Wuwoo Avatar answered Nov 14 '22 23:11

Wuwoo