Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update shared libraries without restarting processes

If my process is loading a .so library and if a new version of the library is available is it possible to switch to the new library without doing a process restart ? Or the answer depends on things like whether there is a parameter change to one of the existing functions in the library ?

I am working in a pretty big system which runs 100s of processes and each loading 10s of libraries. The libraries provide specific functionality and are provided by separate teams. So when one of the library changes (for a bug fix lets say) ideal thing would be to publish it under-the-hood without impacting the running process. Is it possible ?

EDIT Thanks! In my case when a new library is available all the running processes have to start using it. Its not option to let them run with the old version and pick-up the new one later. So it looks like the safer option is to just reload the processes.

like image 727
Manohar Avatar asked Apr 03 '12 20:04

Manohar


2 Answers

Linux provides several dynamic loader interfaces, and process can load dynamic librarys when running. dlopen and dlsysm provided by linux may solve your problem.

like image 106
FCBusquest Avatar answered Sep 20 '22 12:09

FCBusquest


One interesting technique, although it is somewhat prone to failure in the checkpoint restore step, is to do an invisible restart.

Your server process or whatever it is, saves all its necessary information into disk files. Including the file descriptor numbers and current states. Then, the server process does an exec system call to execute itself, replacing the current version of itself. Then it reads its state from the disk files and resumes serving its file descriptors as if nothing happened.

If all goes well, the restart is invisible and the new process is using all of the updated libraries.

like image 27
Zan Lynx Avatar answered Sep 18 '22 12:09

Zan Lynx