无需重新启动进程即可更新共享库 [英] Update shared libraries without restarting processes

查看:35
本文介绍了无需重新启动进程即可更新共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的进程正在加载 .so 库,并且有新版本的库可用,是否可以在不重启进程的情况下切换到新库?或者答案取决于诸如库中现有函数之一是否有参数更改之类的事情?

我在一个相当大的系统中工作,该系统运行 100 个进程,每个进程加载 10 个库.这些库提供特定的功能,由不同的团队提供.因此,当其中一个库发生变化时(例如修复错误),理想的做法是在不影响运行过程的情况下在后台发布它.可能吗?

编辑谢谢!在我的情况下,当一个新库可用时,所有正在运行的进程都必须开始使用它.让他们运行旧版本并在以后选择新版本并不是一种选择.所以看起来更安全的选择是重新加载进程.

解决方案

您无法在进程运行时即时升级链接库.您甚至可以尝试这样做,但如果您成功了(并且您不会因文本文件正在使用"错误消息而失败),您将必须重新启动该过程,使其将新库映射到内存中.

您可以使用 lsof 命令来检查哪些库被链接(运行时或链接时):

lsof -p |grep '内存'

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.

解决方案

You cannot upgrade a linked library on the fly with a process running. You could even try to, but if you succed (and you'll not fail with a "text file is in use" error message), you'll have to restart the process to make it mapping the new library into memory.

You can use lsof command to check which libraries are linked in (runtime or linktime):

lsof -p <process_pid> | grep ' mem '

这篇关于无需重新启动进程即可更新共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆