[英]POSIX message queues - Error on open: Invalid argument
I have trouble with creating a message queue on linux. 我在linux上创建消息队列时遇到了麻烦。 The error I'm getting is "Invalid argument".
我得到的错误是“无效的参数”。 Another thing I have to mansion is that the code is a part of Qt project.
我要做的另一件事是代码是Qt项目的一部分。
Common mistakes are the name does not start with (/) and the number of arg is not correct, but I have checked those! 常见的错误是名称不以(/)开头且arg的数量不正确,但我检查了那些!
here is the code that I'm trying to run: 这是我正在尝试运行的代码:
#define MQ_TEST_PATH "/test_queue"
#define MQ_MAX_MSG_SIZE 256
#define MQ_MAX_MSG_COUNT 20
struct mq_attr mqAttr;
mqAttr.mq_maxmsg = MQ_MAX_MSG_COUNT;
mqAttr.mq_msgsize = MQ_MAX_MSG_SIZE;
mq_unlink(MQ_TEST_PATH);
mode_t mode = S_IRUSR | S_IWUSR;
int oflags = O_WRONLY | O_CREAT | O_EXCL;
mqd_t mqd;
mqd = mq_open(MQ_TEST_PATH, oflags, mode, &mqAttr);
if(mqd < 0){
perror("Error on open");
qDebug()<<mqd;
return 0;
}
mq_close(mqd);
mq_unlink(MQ_TEST_PATH);
Output: 输出:
Error on open: Invalid argument
-1
man mq_open 男子mq_open
EINVAL
O_CREAT
was specified inoflag
, andattr
was notNULL
, butattr->mq_maxmsg
orattr->mq_msqsize
was invalid.EINVAL
O_CREAT
在oflag
中指定,attr
不为NULL
,但attr->mq_maxmsg
或attr->mq_msqsize
无效。 Both of these fields must be greater than zero.这两个字段都必须大于零。 In a process that is unprivileged (does not have the
CAP_SYS_RESOURCE
capability),attr->mq_maxmsg
must be less than or equal to themsg_max
limit在没有特权的进程中(没有
CAP_SYS_RESOURCE
功能),attr->mq_maxmsg
必须小于或等于msg_max
限制
man mq_overview 男子mq_overview
> /proc/sys/fs/mqueue/msg_max > / proc / sys / fs / mqueue / msg_max
The default value for msg_max is 10.
msg_max的默认值为10。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.