如何在两个应用程序之间共享单个共享库 (*.so) 实例 [英] how to share a single shared library(*.so) instance between two applications

查看:98
本文介绍了如何在两个应用程序之间共享单个共享库 (*.so) 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前创建了一个共享库(libshared.so),其中包含一个变量a",它将被共享库api修改.我有两个应用程序 app1 和 app2.app1 正在使用共享库api,它改变了a"的值.现在在 app2 运行时同时进行应该会看到更改后的值.这违背了共享库的实际使用,作为 shared 的单独实例将为每个应用程序创建库.现在我想在两个 app1 和 app2 之间使用共享库的单个实例,以便他们可以看到共享库的相同代码和数据段.是否有任何可能的方法来实现这一点,通过改变 gcc 链接器标志

I currently created a shared library(libshared.so), which contains a variable "a", which will be modified by shared library api. i have two applications app1 and app2. app1 is using shared library api, which changes the value of "a". now simultaneously when app2 is running should see the changed value. This is against the actual usage of shared library, as separate instance of shared library will be created for every application. now i want to use a single instance of shared library between two app1 and app2, so that they can see same code and data segment of shared library. Is there any possible way to achieve this, by altering gcc linker flags

推荐答案

这些回答:

会打破您对共享库方法的期望.

Would shatter your expectation from the shared library approach.

我建议您查看共享内存POSIX API shmget.

一个进程将充当服务器并创建共享内存并向客户端提供共享内存密钥.

One process would act as a server and create the shared memory and provide the shared memory key to the client.

另一种方法是创建一个管道来在进程之间共享数据

Another approach would be to create a pipe to share data between the process

您可以阅读此页面以了解有关进程间通信的更多信息在 Linux 上

You could read this page to have more information about inter process communication on linux

这篇关于如何在两个应用程序之间共享单个共享库 (*.so) 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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