但是交叉编译后在开发板上运行就失败, 返回-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 }
麻烦大家帮我看看问题出在哪里, 提前谢谢了!!!
原因已经找到, 是内核编译出了点问题...