开发者

Which all processes are using shared library

I have a shared library(.so file) on UNIX. I need to know what all running processes are using it. Do unix pr开发者_如何学运维ovide any such utility/command?


You can inspect the contents of /proc/<pid>/maps to see which files are mapped into each process. You'll have to inspect every process, but that's easier than it sounds:

$ grep -l /lib/libnss_files-2.11.1.so /proc/*/maps
/proc/15620/maps
/proc/22439/maps
/proc/22682/maps
/proc/32057/maps

This only works on the Linux /proc filesystem, AFAIK.


A quick solution would be to use the lsof command

[root@host]# lsof /lib/libattr.so.1
COMMAND     PID USER  FD   TYPE DEVICE  SIZE   NODE NAME
gdm-binar 11442 root mem    REG    8,6 30899 295010 /lib/libattr.so.1.1.0
gdm-binar 12195 root mem    REG    8,6 30899 295010 /lib/libattr.so.1.1.0

This should work not only for .so files but any other files, dirs, mount points, etc.

N.B. lsof displays all processes that use a file, so there is a very remote possibility of a false positive if is a process that opens the *.so file but not actually use it. If this is an issue for you, then Marcelo's answer would be the way to go.


Do in all directories of interest

ldd * >ldd_output
vi ldd_output

Then look for the the library name, e.g. “aLib.so”. This shows all modules linked to e.g. "aLib.so"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜