共享内存shm_open vs shmget--之跨用户共享


    shm_open() allows multiple un-related processes to access the same shared memory - since it can be accessed by a well know name.
shmget() requires some way for the creating process to give the 'key' used to create the memory to other processes so they can access it. sometimes the creating process writes the 'key' to a well known file name so that other un-related processes can read the key.
if the creating process only needs to share the memory with child processes created via fork(), then shmget() is ok; otherwise, shm_open() is often used.

 

    在跨用户访问共享内存时,shm_open会好一些,因为它的文件是放在/dev/shm的这么一个公共目录。 shmget还要特意找一个区域让多用户共享,然后再生成个不会被删除的文件来生成共享key,这样不如shm_open来的直接和明确。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM