views:

283

answers:

4

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.

thx

AC

+1  A: 

you can use lsof. See the man page for more info. Another tool is strace. To see if a process is launched, you can use ps -ef piped to grep, or tools like pgrep as well. check for the return value to know if its quit or not.

ghostdog74
+4  A: 

if lsof is not installed, you can simply cat /proc/$pid/maps

you can also check on disk executables with ldd to see what libs they will open (but that doesn't show libraries opened dynamically using dlopen()).

As for monitoring new processes, you can possibly add an inotify watch on /proc to monitor the creation/destruction of new numeric only directories.

Update: inotify on /proc doesn't work, but there are apparently alternatives, see this thread

ggiroux
+1  A: 

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.

Nikolai N Fetissov
A: 

I think i didnt 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++.

thx

Alexander Cohen