linux shm_open,c – 如何更改shm_open路径?
我目前正在ubunto上開發一個應用程序并調用shm_open,目前默認路徑在/ var / run / shm內.但是我需要將其更改為/ tmp.只是嘗試以下操作不起作用:
fd = shm_open(“/ tmp / test”,O_RDWR | O_CREAT,0777);
任何人都可以建議嗎?
解決方法:
從shm_open(3)的手冊頁:
name specifies the shared memory object to be created or opened. For portable use, a shared memory object should be identified by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters consisting of an initial slash, followed by one or more characters, none of which are slashes.
shm_open(3)的name參數是對象名,而不是文件路徑!只是GLIBC將所有共享內存對象放在/ dev / shm或/ var / run / shm中,方法是在路徑前加上對象名,并在結果名稱上調用open().如果指定/ tmp / test作為共享對象名,則Linux將嘗試打開或創建/ var / run / shm / tmp / test.使用O_CREAT打開會創建新文件,但不會創建新目錄.
如果您在調用shm_open(“/ tmp / test”,…)之前首先創建目錄/ var / run / shm / tmp,那么您的測試將起作用.完成共享內存對象的使用后,請記住將其刪除.并且還要注意,使用帶有兩個斜杠的對象名稱可能無法移植到其他Unix系統.
標簽:c,linux,boost,shared-memory
來源: https://codeday.me/bug/20190723/1512607.html
總結
以上是生活随笔為你收集整理的linux shm_open,c – 如何更改shm_open路径?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android pdu 编码规则,[转载
- 下一篇: dlopen linux 实例_Linu