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

后端 未结 7 467
梦如初夏
梦如初夏 2020-12-23 20:30

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 nee

7条回答
  •  失恋的感觉
    2020-12-23 21:11

    On Mac OS X you can use vmmap $pid to get a list of mapped memory regions for a process. This does show all loaded libraries (at least it works for me here on 10.7.5).

    ps -A will give you a list of all processes, so ps -A | grep $APPNAME will get you your process id $pid for use with vmmap $pid. lsof -p $pid also works.

    The question seems to be asking for a dynamic method from C++. You could poll with these commands and analyse the results, although you may miss fast load/unload events.

    lsof is open source software under a BSD licence. Its source code no doubt provides some insight for how to do this from C/C++. See: http://en.wikipedia.org/wiki/Lsof

提交回复
热议问题