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.

Kanwar Saad
  • 153
  • 1
  • 1
  • 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. – countermode Mar 02 '15 at 22:57
  • i mean running processes. – Kanwar Saad Mar 02 '15 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. – ctrl-alt-delor Mar 02 '15 at 23:09
  • 1
    http://unix.stackexchange.com/questions/181697/how-do-i-detect-running-processes-using-a-library-package?rq=1 – ctrl-alt-delor Mar 02 '15 at 23:13
  • 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. – Kanwar Saad Mar 02 '15 at 23:14

1 Answers1

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.

Firelord
  • 342
  • 1
  • 17
  • 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-*'``` – dmytro.poliarush Nov 04 '19 at 08:41