Linux mq_open: 无效参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9997460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mq_open: Invalid argument
提问by yellowantphil
I'm trying to run the example program for POSIX message queues found in the man pagefor mq_notify. I'm running it as ./mq '/bla'
and it gives me the error mq_open: Invalid argument
.
我正在尝试运行mq_notify手册页中的 POSIX 消息队列示例程序。我正在运行它./mq '/bla'
,它给了我错误mq_open: Invalid argument
。
This is the line in the sample program that gives the error:
这是示例程序中给出错误的行:
mqdes = mq_open(argv[1], O_RDONLY);
I've tried changing it to
我试过把它改成
mqdes = mq_open("/bla", O_RDONLY | O_CREAT);
but it still doesn't work.
但它仍然不起作用。
This must be simple, but I can't figure it out. What am I doing wrong?
这一定很简单,但我无法弄清楚。我究竟做错了什么?
This is RHEL 5.8, by the way.
顺便说一下,这是 RHEL 5.8。
EDIT:I was wrong about the first error. Without O_CREAT, it said "No such file or directory". I guess it was trying to open a message queue that didn't exist. With O_CREAT, I think the invalid argument error was because I only had two arguments, and you need four with O_CREAT.
编辑:我错了第一个错误。没有 O_CREAT,它说“没有这样的文件或目录”。我猜它试图打开一个不存在的消息队列。对于 O_CREAT,我认为无效参数错误是因为我只有两个参数,而 O_CREAT 需要四个。
采纳答案by nos
Just mq_open(argv[1], O_RDONLY);
should fail with "ENOENT (No such file or directory)" if the message queue does not exist.
只是mq_open(argv[1], O_RDONLY);
应失败“ENOENT(没有这样的文件或目录)”如果消息队列不存在。
If you change it to use O_CREAT, you need to pass 2 additional arguments to mq_open(). (read the paragraph about O_CREAT).e.g.
如果将其更改为使用 O_CREAT,则需要向mq_open()传递 2 个附加参数。(阅读关于 O_CREAT 的段落)。例如
mq_open(argv[1], O_RDONLY | O_CREAT, 0666, NULL);