0
我試圖使用POSIX4消息隊列。所以我使用mq_open
來創建隊列,並且我給它的所有選項都填充了struct mq_attr
。POSIX4消息隊列「mq_open:沒有這樣的文件或目錄」
他找不到隊列,而我把O_CREATE
標誌。
這裏是我的代碼(無縮入行調試代碼):
...
/***
* Queues' names
*/
#define GUI_QUEUE "/guiQ"
...
struct mq_attr attrAct; /* Queue parameters */
/***
* Message queue to send action
*/
attrAct.mq_maxmsg=1;
attrAct.mq_msgsize=sizeof(gui_action);
attrAct.mq_flags=0;
attrAct.mq_curmsgs=0;
printf("serveur first sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), attrAct.mq_msgsize);
if ((guiQue=mq_open(GUI_QUEUE, O_CREAT | O_NONBLOCK | O_WRONLY
, S_IWUSR | S_IRUSR , &attrAct))!=0) {
perror("mq_open");
exit(EXIT_FAILURE);
}
if (mq_getattr(guiQue, &attrAct)!=0) {
perror("mq_getattr");
}
else {
printf("serveur second sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), attrAct.mq_msgsize);
}
struct mq_attr new;
new=attrAct;
new.mq_msgsize=sizeof(gui_action);
printf("serveur third sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), new.mq_msgsize);
if (mq_setattr(guiQue, &new, &attrAct)!=0) perror("mq_setattr");
if (mq_getattr(guiQue, &attrAct)!=0) {
perror("mq_getattr");
}
else {
printf("serveur fourth sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), attrAct.mq_msgsize);
}
...
這裏是輸出:
serveur first sizeof(gui_action) : 16 msgsize : 16
mq_open: No such file or directory
我在做什麼錯?
您試圖在文件系統的根目錄上打開一個隊列。該代碼沒有權限這樣做。 – t0mm13b
是的,但是如果我把''guiQ /「'或''guiQ'',有一個無效的參數錯誤。那麼,我如何在用戶空間打開一個mq? (即使使用'sudo',它也不起作用) – Phantom
檢查編譯的可執行代碼所在的目錄,如果沒有'guiQ',則需要提供更多的調試信息,'errno' ?在根中使用它,即'/'不是正確的地方。 – t0mm13b