共享內存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