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?
Shared Libraries are loaded by the executable (or other shared library) at runtime.
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.
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'
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With