Sharing shared object between multiple processes

自古美人都是妖i 提交于 2019-12-24 02:13:54

问题


Are shared objects separately loaded for each process or one shared object is shared among them? For example, let's say that some program uses libc.so. Then two processes of this program are launched. Will be this shared object loaded TWO times for each process in their memory area OR will it be loaded somewhere in memory ONCE and mapped in memory of two processes?


回答1:


Shared objects are loaded via mmap() with the MAP_PRIVATE flag. This means that these are copy-on-write mappings, they initially point to the same memory, but once any of them is modified, it is copied and "unshared" before the modification.




回答2:


Check this thread. In theory each process holds each it's own address space, and threads should be used for such purpose, but it's a matter of system implementation.



来源:https://stackoverflow.com/questions/11618543/sharing-shared-object-between-multiple-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!