看板 C_and_CPP 關於我們 聯絡資訊
各位好, 最近在看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即可 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.236.122.178 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1568984960.A.5CB.html
Schottky: 看 man page 的 creat (2) 就有詳細介紹 09/20 21:14
Schottky: 跟檔案的 mode 一樣意思,新開 shm 時以此為預設 mode 09/20 21:15
Schottky: 這也就是有 O_CREAT 才需要指定 mode 的原因 09/20 21:15
Schottky: shm_open沒寫應該是假設你已經把open背到滾瓜爛熟了 XD 09/20 21:16
Schottky: 如果看不懂 open / creat 的說明,建議可以再看看 09/20 21:22
Schottky: chmod (1) 和 chmod (2) 的 man page,1 是 shell 指令 09/20 21:23
Schottky: 2 是 system call 09/20 21:23
eecheng87: 感謝大大提示,原來666是檔案開到最大權限。可讀可寫。 09/20 21:56
LPH66: 777 才是喔, 因為還有執行權限 09/21 01:24