共享内存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来的直接和明确。

 

posted @ 2021-11-18 17:00  dzqabc  阅读(41)  评论(0编辑  收藏  举报