3

I know that ldd utility can list all libraries linked to a process but I want it the other way around. I want all processes linked to a library. I want to replace a shared library without crashing the system and make sure that the process reads the new library. A safe way is to check how many processes are using it and then shut them down using a script, replace the library and start them again. I'll be really glad if there is a better way to do it. thanks in advance.

5
  • Do you really mean processes (i.e. running programs) or do you mean program binaries? For the former you can use lsof, the latter requires ldd-ing all programs binaries you're interested in (typically /bin/*, /sbin/*, /usr/sbin/* and so on) and grepping for the shared lib you're interested in. Mar 2, 2015 at 22:57
  • i mean running processes. Mar 2, 2015 at 23:01
  • If a process is linked to a shared library, and you delete the library, then the process will be fine. Though no disk blocks will be freed until all processes stop using the library (this is true of all files on Unix systems). The only problem could be if there are version dependencies i.e. lib-a version1 depends on lib-b version1, and lib-a version2 depends on lib-b version2. In that case there could be a race problem on process load. Mar 2, 2015 at 23:09
  • 1
  • the API of the library is not changed so I can safely replace the lib. But I cant figure out a proper way to replace the binary. The processes using the library crashes when I replace the current binary. Mar 2, 2015 at 23:14

1 Answer 1

6

Typically, for finding the processes sharing the library, you can use the command lsof shared_library_path. It will list out all the processes. Source : Here
A Similar question was asked before here.

1
  • 1
    +d flag of lsof can be useful when searching open files in a given directory. Like so: lsof +d /usr/lib/arm-linux-gnueabihf/ | grep -i 'libhw-*' Nov 4, 2019 at 8:41

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