62

I have two, related questions:

  • How can I see if a shared library is currently loaded? (i.e. system-wide, process agnostic)
  • How can I see all shared libraries loaded by a process?

4 Answers 4

71

You can do both with lsof. To see what processes have a library open or mapped do:

lsof /path/to/lib.so

and to see what files (including shared libraries) a process has open and/or mapped, do:

lsof -p <pid>
2
  • That only helps if you know WHICH instance of a .so file is loaded. Is it possible to list all th e.so files actually used by an app to find the disk path to the one I need?
    – will
    Mar 26, 2020 at 7:38
  • It's also better to run these commands with root rights (e.g. sudo) to aovid missing some processes
    – leokom
    Oct 31, 2022 at 8:32
33

Another way to see what's loaded in a process is by looking at the /proc/PID/maps file. This shows everything mapped into your address space, including shared objects mapped in.

1
  • Worked fine on my embedded ARM platform. While the BusyBox implementation of lsof did not have the needed functionality.
    – Alex Che
    Sep 26, 2018 at 7:53
11
sudo grep libcairo.so /proc/*/maps

is a nice way to explore all /proc/PID/maps mentioned by Rich at once. Sample output:

/proc/8390/maps:7f0a9afae000-7f0a9b0bc000 r-xp 00000000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8390/maps:7f0a9b0bc000-7f0a9b2bc000 ---p 0010e000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8390/maps:7f0a9b2bc000-7f0a9b2bf000 r--p 0010e000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8390/maps:7f0a9b2bf000-7f0a9b2c0000 rw-p 00111000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8466/maps:7f0a9afae000-7f0a9b0bc000 r-xp 00000000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8466/maps:7f0a9b0bc000-7f0a9b2bc000 ---p 0010e000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8466/maps:7f0a9b2bc000-7f0a9b2bf000 r--p 0010e000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
/proc/8466/maps:7f0a9b2bf000-7f0a9b2c0000 rw-p 00111000 fc:00 274690                     /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6

Further awk and bash-fu can refine the output further.

This method also shows libraries opened with dlopen, tested with this minimal setup hacked up with a sleep(1000) on Ubuntu 18.04.

8

You can run the next command by root and see a full list,

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

This is for users who don't have lsof.

1
  • 1
    Why do you want the user to try that? Please edit your answer to better understanding.
    – CaldeiraG
    May 3, 2018 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .