[問題] shm_open 參數問題

作者: eecheng87 (EEcheng)   2019-09-20 21:09:18
各位好, 最近在看POSIX用shared memory實作IPC system, 其中
出現了 shm_open這個函數, 而讓我覺得困惑的是他的最後一個
參數 mode_t mode, 我在linux manual中看他描述這個函數的
所有參數卻獨獨漏了最後一個 mode_t mode的描述, 而且恐龍
本也只簡單說這個參數
establishes the directory permissions of the shared memory
object.
我想請問一下, 有人知道這個參數所對應的數字分別代表甚麼意思嗎?
目前我看到的有0666和0777
以下附上範例呼叫方式:
shm_open(name, O_CREAT | O_DRAW, 0666)
另外補充一點, 我有看到資料有說若有O_CREAT才需要特別注意最後一個
參數, 其他只要填0即可
作者: Schottky (順風相送)   2019-09-20 21:14:00
看 man page 的 creat (2) 就有詳細介紹跟檔案的 mode 一樣意思,新開 shm 時以此為預設 mode這也就是有 O_CREAT 才需要指定 mode 的原因shm_open沒寫應該是假設你已經把open背到滾瓜爛熟了 XD如果看不懂 open / creat 的說明,建議可以再看看chmod (1) 和 chmod (2) 的 man page,1 是 shell 指令2 是 system call
作者: eecheng87 (EEcheng)   2019-09-20 21:56:00
感謝大大提示,原來666是檔案開到最大權限。可讀可寫。
作者: LPH66 (-6.2598534e+18f)   2019-09-21 01:24:00
777 才是喔, 因為還有執行權限

Links booklink

Contact Us: admin [ a t ] ucptt.com