Find so from /proc/pid/maps Only works with libraries that has already been loaded. But this is the most accurate method -- it finds the exact library that's being used.
(name)
| 243 | return find_library(name) |
| 244 | |
| 245 | def _use_proc_maps(name): |
| 246 | """ |
| 247 | Find so from /proc/pid/maps |
| 248 | Only works with libraries that has already been loaded. |
| 249 | But this is the most accurate method -- it finds the exact library that's being used. |
| 250 | """ |
| 251 | procmap = os.path.join('/proc', str(os.getpid()), 'maps') |
| 252 | if not os.path.isfile(procmap): |
| 253 | return None |
| 254 | try: |
| 255 | with open(procmap, 'r') as f: |
| 256 | for line in f: |
| 257 | line = line.strip().split(' ') |
| 258 | sofile = line[-1] |
| 259 | |
| 260 | basename = os.path.basename(sofile) |
| 261 | if 'lib' + name + '.so' in basename: |
| 262 | if os.path.isfile(sofile): |
| 263 | return os.path.realpath(sofile) |
| 264 | except IOError: |
| 265 | # can fail in certain environment (e.g. chroot) |
| 266 | # if the pids are incorrectly mapped |
| 267 | pass |
| 268 | |
| 269 | # The following two methods come from https://github.com/python/cpython/blob/master/Lib/ctypes/util.py |
| 270 | def _use_ld(name): |
no test coverage detected