博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POSIX消息队列mq_open问题
阅读量:4049 次
发布时间:2019-05-25

本文共 1357 字,大约阅读时间需要 4 分钟。

遇到 mq_open: Permission denied

请看:

Mounting the message queue file system

       On Linux, message queues are created in a virtual file system.   (Other
       implementations  may  also  provide such a feature, but the details are
       likely to differ.)  This file system can be mounted (by the  superuser)
       using the following commands:
           # mkdir /dev/mqueue
           # mount -t mqueue none /dev/mqueue

执行上面两条命令OK,

还是遇到同样的问题:

再看

Each message queue  is  identi fied by a name of the form /somename.  Two processes can operate on the

same queue by passing the same name to mq_open().

也就是说,消息的队列的命名方式为/mq_name

其它命名方式都不对,像/tmp/mq.2342是不对的。

OK,以下为测试代码:

/* ============================================================================ Name        : mq_creat.c ============================================================================ */#include 
#include
#include
#include
#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)int main(int argc, char** argv) { mqd_t mqd; int c, flags; flags = O_RDWR | O_CREAT; while ((c = getopt(argc, argv, "e")) != -1) { switch (c) { case 'e': flags |= O_EXCL; break; } } if (optind != argc - 1) { printf("Invalid arg\n"); return 1; } mqd = mq_open(argv[optind], flags, FILE_MODE, NULL); if (mqd == -1) { perror("mq_open"); return 2; } mq_close(mqd); return 0;}

不懂一定要看man pages, 

如:man 7 mq_overview

转载地址:http://ytcci.baihongyu.com/

你可能感兴趣的文章
GBK编码下jQuery Ajax中文乱码终极暴力解决方案
查看>>
Oracle 物化视图
查看>>
PHP那点小事--三元运算符
查看>>
解决国内NPM安装依赖速度慢问题
查看>>
Brackets安装及常用插件安装
查看>>
Centos 7(Linux)环境下安装PHP(编译添加)相应动态扩展模块so(以openssl.so为例)
查看>>
fastcgi_param 详解
查看>>
Nginx配置文件(nginx.conf)配置详解
查看>>
标记一下
查看>>
IP报文格式学习笔记
查看>>
autohotkey快捷键显示隐藏文件和文件扩展名
查看>>
Linux中的进程
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
自然计算时间复杂度杂谈
查看>>
当前主要目标和工作
查看>>
使用 Springboot 对 Kettle 进行调度开发
查看>>
一文看清HBase的使用场景
查看>>
解析zookeeper的工作流程
查看>>
搞定Java面试中的数据结构问题
查看>>