[结贴][求助] 消息队列 | 使用msgget函数失败

内核编译和嵌入式产品的设计与开发
回复
头像
iceway
帖子: 33
注册时间: 2007-10-15 9:08
来自: Xiamen, China

[结贴][求助] 消息队列 | 使用msgget函数失败

#1

帖子 iceway » 2008-12-26 16:19

我编写程序使用msgget函数创建一个消息队列, 程序在本地pc上没有任何问题,
但是交叉编译后在开发板上运行就失败, 返回-1, 按照手册说明, 应该是把errno设置成以下宏中的一个:

On failure, errno is set to one of the following values:

EACCES A message queue exists for key, but the calling process does not have permission to access the queue,
and does not have the CAP_IPC_OWNER capability.

EEXIST A message queue exists for key and msgflg specified both IPC_CREAT and IPC_EXCL.

ENOENT No message queue exists for key and msgflg did not specify IPC_CREAT.

ENOMEM A message queue has to be created but the system does not have enough memory for the new data struc‐
ture.

ENOSPC A message queue has to be created but the system limit for the maximum number of message queues
(MSGMNI) would be exceeded.


可是我的程序运行时, errno被设置成89, 上述的5个宏都不是89,
把问题帖出来, 希望大家能帮帮忙看看.

我的测试程序如下:

代码: 全选

  1 #include <stdio.h>
  2 #include <sys/types.h>
  3 #include <sys/ipc.h>
  4 #include <sys/msg.h>
  5 #include <string.h>
  6 #include <errno.h>
  7
  8 int main()
  9 {
 10         key_t mqkey;
 11         int oflag, mqid;
 12
 13         char filenm[]="mq";
 14         oflag=IPC_CREAT;
 15
 16         mqkey=ftok(filenm, 0xFF);
 17         if(mqkey == -1){
 18                 printf("ftok error, errno = %d\n", errno);
 19         }else{
 20                 printf("ftok ok\n");
 21         }
 22
 23         mqid=msgget(mqkey, oflag);
 24         if(mqid == -1){
 25                 printf("msgget error, errno = %d\n", errno);
 26         }else{
 27                 printf("msgget ok\n");
 28         }
 29
 30         return 0;
 31 }

麻烦大家帮我看看问题出在哪里, 提前谢谢了!!!


原因已经找到, 是内核编译出了点问题...
有些故事还没讲完, 那就算了吧;有些心情在岁月中, 已经难辨真假。
bitbybit.72pines.com
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: [结贴][求助] 消息队列 | 使用msgget函数失败

#2

帖子 qry » 2017-03-24 10:46

你好,我现在也遇到同样的问题,不知道你当时是怎么解决的?看到的话能否回一下,谢谢
回复