如何检查给定进程在运行时加载了哪些共享库? [英] How to check what shared libraries are loaded at run time for a given process?

查看:95
本文介绍了如何检查给定进程在运行时加载了哪些共享库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查正在使用哪个库?

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

更具体地说,如果程序使用 dlopen 加载某些共享库,则readelf或ldd不是要显示它. 是否有可能从正在运行的进程中获取该信息?如果是,怎么办?

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?

推荐答案

其他人处在正确的轨道上.这有几种方法.

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

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

或者,使用strace:

Or, with strace:

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

这两个都假设共享库的路径中有".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.

当然还有lsof ...

lsof -p NNNN | awk '{print $9}' | grep '\.so'

这篇关于如何检查给定进程在运行时加载了哪些共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆