how to get list of all processes accessing a shared library

12,076

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.

Share:
12,076

Related videos on Youtube

Kanwar Saad
Author by

Kanwar Saad

Updated on September 18, 2022

Comments

  • Kanwar Saad
    Kanwar Saad over 1 year

    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
      Kanwar Saad about 9 years
      i mean running processes.
    • ctrl-alt-delor
      ctrl-alt-delor about 9 years
      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.
    • Kanwar Saad
      Kanwar Saad about 9 years
      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.
  • dmytro.poliarush
    dmytro.poliarush over 4 years
    +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-*'