【发布时间】:2012-02-11 08:36:29
【问题描述】:
我编写了这段代码来创建一个 posix 消息队列。但我收到“功能未实现”错误。
第一季度。是平台相关的问题吗? [正在使用 Ubuntu 10.10] 我在某处读到需要重建内核以启用消息队列!?
第二季度。我还阅读了一些关于在实际使用消息队列之前启动 mqueue 服务器的内容?
谁能解释一下..
#include <mqueue.h> /* message queue stuff */
#include <iostream>
#include <unistd.h> /* for getopt() */
#include <errno.h> /* errno and perror */
#include <fcntl.h> /* O_flags */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(int argc, char **argv)
{
mqd_t msgQueueDescriptor;
mq_attr attr;
char Msg[]="msg";
attr.mq_maxmsg = 10;
attr.mq_msgsize = sizeof(Msg);
attr.mq_flags = 0;
msgQueueDescriptor = mq_open("/myQueue", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH , attr );
cout << msgQueueDescriptor << " " << errno << " " << strerror(errno);
mq_close(msgQueueDescriptor);
return 0;
}
【问题讨论】:
-
根据
mq_overview(7),POSIX 消息队列在构建内核时默认启用,但 Ubuntu 打包程序可能已将其关闭。 -
@larsmans 我该如何确认?这会成为 Ubuntu 发行说明的一部分吗?如果它真的关闭了,我该如何重新打开它?
-
如果 ubuntu 真的把它们关掉的话,我会觉得很奇怪。在 fedora 15 上,您的示例编译和链接成功。
-
您可能想通过 Synaptic 下载内核源代码包并检查其配置;你得到的错误肯定是
ENOSYS,这意味着没有系统调用。我认为打开 MQ 将涉及重新编译内核。不过,如果默认内核不支持 MQ,我会感到非常惊讶。 -
这在 Ubuntu 10.04.3 上编译、链接和运行。验证您的内核是否配置了所需的标志。看看
/boot/config*。
标签: c++ linux posix message-queue ubuntu-10.10