如何在linux的许多应用程序中有一个共享变量? [英] how to have a shared variable in library across many applications in linux?
本文介绍了如何在linux的许多应用程序中有一个共享变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在linux(c ++)中的所有应用程序中使用库中的共享变量?
how to have a shared variable in library across all application in linux (c++)?
推荐答案
内存创建一个共享内存段,并将变量放在那里。您将需要使用POSIX信号量同步对共享变量的访问。
You can use POSIX shared memory to create a shared memory segment, and place the variable there. You will need to synchronise access to the shared variable using POSIX semaphores.
请参阅 shm_overview(7)和 sem_overview(7)手册页开始。
这篇关于如何在linux的许多应用程序中有一个共享变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文