Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of used libraries by a running process (unix)

I need to find out what libraries a unix process has loaded and might use throughout it's lifetime. Is this possible and how. Or better yet, i have a library name and i need to find out what processes are using it, is this possible.

On the same note, is it possible to get notified some how when a unix process is launched and when it is quit. They would not be child processes of my process, i just need to know globally.

Update:

I think I didn't give enough information. The unix i was talking about was MacOS X ( even though some say its not really completely unix ), and I was looking for a way to find the loaded libraries a process has and i need to do it in C/C++.

like image 204
Alexander Cohen Avatar asked Feb 02 '10 14:02

Alexander Cohen


People also ask

How do I list libraries in Linux?

By default, libraries are located in /usr/local/lib, /usr/local/lib64, /usr/lib and /usr/lib64; system startup libraries are in /lib and /lib64. Programmers can, however, install libraries in custom locations. The library path can be defined in /etc/ld.

How do I find library dependencies?

Use objdump -p libABCD.so | grep NEEDED to view dependencies on individual library files. Then follow on the output libraries. Show activity on this post. Instead of giving the boost libraries as -l on the linker command line, you can also give them with their full path and file name.

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.


1 Answers

Solaris has pldd. For Linux you can call ldd on the executable or pmap on a running process or look into /proc/PID/maps for mapped libraries.

like image 184
Nikolai Fetissov Avatar answered Sep 24 '22 01:09

Nikolai Fetissov