linux中消息队列的问题

allex1226 2011-01-05 09:13:00
在linux中,首先init队列
nMsqId = msgget (msq_key, 0660|IPC_CREAT),成功

但是执行 nReturnCode = msgctl (nMsqId, IPC_STAT, &tMsqidDs);取队列状态时报错

nReturnCode=1998850
nReturnCode: Invalid or incomplete multibyte or wide character

在sco-unix下执行是通过的,但是在linux下执行错误。
请教各位
...全文
172 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wickyboy 2011-01-06
  • 打赏
  • 举报
回复
楼主的问题解决了吗?
wickyboy 2011-01-05
  • 打赏
  • 举报
回复
你的KEY是用什么得到的,我是用ftok(".", 'a')得到的。

还有你用的那个LINUX系统?UBUNTU 还是 FD, 我刚刚写了一下,没有报错,通过了的

#include <sys/msg.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <unistd.h>

int main(){

key_t key = ftok(".", 'a');

int nMsgId = msgget(key, 0660 | IPC_CREAT);
if(nMsgId < 0){
perror("msgget");
exit(-1);
}

struct msqid_ds tMsqidDs;
int ret = msgctl(nMsgId, IPC_STAT, &tMsqidDs);
if(ret < 0){
perror("msgctl");
exit(-1);
}
return 0;
}
wickyboy 2011-01-05
  • 打赏
  • 举报
回复
http://linux.die.net/man/2/msgctl

我看上面说的是宽字符的什么问题,奇怪啊。而且你的错误返回值怎么会是正数?你查下错误代码代表的错误定义是什么?这样可以准确地找到原因
allex1226 2011-01-05
  • 打赏
  • 举报
回复
使用IPC_64也不行啊,还报同样的错误
allex1226 2011-01-05
  • 打赏
  • 举报
回复
nMsqId = msgget (msq_key, 0660|IPC_CREAT),队列是660啊
wickyboy 2011-01-05
  • 打赏
  • 举报
回复
Various fields in the struct msqid_ds were shorts under Linux 2.2 and have become longs under Linux 2.4. To take advantage of this, a recompilation under glibc-2.1.91 or later should suffice. (The kernel distinguishes old and new calls by an IPC_64 flag in cmd.)

看看这个能帮你不?
wickyboy 2011-01-05
  • 打赏
  • 举报
回复
nReturnCode = msgctl (nMsqId, IPC_STAT, &tMsqidDs)

我觉得是不是你的tMsqidDs有问题啊?缓冲有问题?而且你得有消息队列的读权限

allex1226 2011-01-05
  • 打赏
  • 举报
回复
这就是perror("nReturnCode")出来的结果
justkk 2011-01-05
  • 打赏
  • 举报
回复
msgctl失败后,调用perror("msgctl")看看

2,161

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 UNIX文化
社区管理员
  • UNIX文化社区
  • 文天大人
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧