关于POSIX消息队列mq_open提示错误信息:Invalid argument的问题
2017-03-05 21:35
1446 查看
关于POSIX消息队列mq_open提示错误信息:Invalid argument的问题
1. 发现问题
在学习《Unix网络编程》卷二:进程间通信的第五章,p63页代码时,当调用mq_open函数时,总是提示错误信息Invalid argument。最总将错误定位在mq_open函数的第四个参数&attr,当传值为NULL时,程序没错误提示,而&attr时,总是编译提示错误信息。
代码如下:
#include "unpipc.h" struct mq_attr attr; int main(int argc, char *argv[]) { mqd_t mqd; int flags, c; flags = O_CREAT | O_RDWR; while( (c = getopt(argc, argv, "em:z:")) != -1) { switch (c) { case 'e': flags |= O_EXCL; break; case 'm': attr.mq_maxmsg = atol(optarg); break; case 'z': attr.mq_msgsize = atol(optarg); break; } } /* printf("optind = %d\n", optind); printf("argc = %d\n", argc); printf("maxmsg #msgs = %ld\nmsgsize #bytes/msg= %ld\ncurmsg = %ld\n", attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs); */ if(optind != argc-1) sys_err("usage:mqcreat [-e] [-m maxmsg -z msgsize] <name>"); if((attr.mq_maxmsg != 0 && attr.mq_msgsize == 0) || (attr.mq_maxmsg == 0 && attr.mq_msgsize != 0)) sys_err("must specify both -m maxmsg and -z msgsize"); mqd = mq_open(argv[optind], flags, FILE_MODE, &attr); if(mqd == -1) sys_err("mq_open err"); printf("mqd = %d\n", mqd); mq_close(mqd); return 0; }
2. 及时总结
在man pages的第7章有关于消息队列的综述。man mq_overview
有一段叫/proc interfaces的标签,说明了一些限制问题。
The following interfaces can be used to limit the amount of kernel memory consumed by POSIX message queues and to set the default attributes for new message queues:
大意为:
以下接口可用于限制被POSIX消息队列消耗,和被设置新消息队列属性所消耗的内核内存量。
并且给出
/proc/sys/fs/mqueue/目录下的文件详细解释
//文件内容如下: msg_default 10 msg_max 10 msgsize_default 8192 msgsize_max 8192 queues_max 256 //本机系统为Ubuntu 16.04 LTS 64位
而UNP书上执行程序参数maxmsg为1024,已经超过系统限制的10。因此,总是提示错误信息:Invalid argument。
当将maxmsg参数大小小于等于10时,程序编译通过。
相关文章推荐
- 消息队列莫名其妙的错误 mq_open失败,Invalid argument
- POSIX消息队列mq_open问题
- 关于消息队列的应用中提示问题
- 关于oracle下提示ORA-00904:Invalid identifier错误的问题
- 关于plsql下提示ORA-00904:Invalid identifier错误的问题
- 关于plsql下提示ORA-00904:Invalid identifier错误的问题----创建表时字段加了引号
- 消息队列函数 msgsnd 出现Invalid argument错误的解决办法
- 在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: ‘文件路径’
- mq_open及linux下posix消息队列
- 关于自定义控件在布局文件中使用时提示error: Error parsing XML: not well-formed (invalid token)错误的问题
- 关于自定义控件在布局文件中使用时提示error: Error parsing XML: not well-formed (invalid token)错误的问题
- 关于IIS安装错误提示:安装程序无法复制文件 zClientm.ex_问题
- 【学习随手记】POSIX消息队列执行报Permission denied的问题。
- 关于struts2验证框架,在与spring整合后重复输出错误信息的问题
- 使用storm处理消息队列中的日志信息遇见的错误
- 关于Eclipse中项目提示错误而文件不显示错误问题的解决
- POSIX 消息队列相关问题
- Posix消息队列使用非阻塞mq_receive的信号通知
- Yii 提示Invalid argument supplied for foreach() 等错误
- 关于安卓微信支付提示未知错误,而IOS正常的处理问题