Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check what shared libraries are loaded at run time for a given process?

Is there a way to check which libraries is a running process using?

To be more specific, if a program loads some shared libraries using dlopen, then readelf or ldd is not going to show it. Is it possible at all to get that information from a running process? If yes, how?

like image 824
BЈовић Avatar asked Feb 24 '11 10:02

BЈовић


People also ask

Where are shared libraries loaded?

Shared Libraries are loaded by the executable (or other shared library) at runtime.

How do you check if a shared library is loaded in Linux?

If the program is already running, we can also get the list of loaded shared libraries by reading the file /proc/<PID>/maps. In this file, each row describes a region of contiguous virtual memory in a process or thread. If the process has loaded a shared library, the library will show up in this file.


2 Answers

Other people are on the right track. Here are a couple ways.

cat /proc/NNNN/maps | awk '{print $6}' | grep '\.so' | sort | uniq 

Or, with strace:

strace CMD.... 2>&1 | grep -E '^open(at)?\(.*\.so' 

Both of these assume that shared libraries have ".so" somewhere in their paths, but you can modify that. The first one gives fairly pretty output as just a list of libraries, one per line. The second one will keep on listing libraries as they are opened, so that's nice.

And of course lsof...

lsof -p NNNN | awk '{print $9}' | grep '\.so' 
like image 68
Dietrich Epp Avatar answered Oct 26 '22 04:10

Dietrich Epp


May be lsof - the swiss army knife of linux will help?

edit: to run, lsof -p <pid>, lists all sorts of useful information, for example, if the process is java, lists all the open jars - very cool...

like image 44
Nim Avatar answered Oct 26 '22 05:10

Nim