zoukankan      html  css  js  c++  java
  • 【学习随手记】POSIX消息队列执行报Permission denied的问题。

    最近学习UNIX环境网络编程POSIX消息队列的时候发现一个问题,在mq_open的时候总会报Permission denied的错误。

    查看mq_overview后才得以解决。

    mq_overview原文描述如下:

    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

           The sticky bit is automatically enabled on the mount directory.

           After  the file system has been mounted, the message queues on the sys‐
           tem can be viewed and manipulated using the commands usually  used  for
           files (e.g., ls(1) and rm(1)).

    创建MQ的代码如下:

     1 #include <unpipc.h>
     2 
     3 int
     4 main(int argc, char **argv)
     5 {
     6     int c, flags;
     7     mqd_t mqd;
     8 
     9     flags = O_RDWR | O_CREAT;
    10 
    11     while ((c = Getopt(argc, argv, "e")) != -1)
    12     {
    13         switch (c) 
    14         {
    15         case 'e':
    16             flags |= O_EXCL;
    17             break;
    18         }
    19     }
    20 
    21     if (optind != argc - 1)
    22         err_quit("usage: mqcreate [-e] <name>");
    23 
    24     mqd = Mq_open(argv[optind], flags, 0777, NULL);
    25     Mq_close(mqd);
    26 
    27     exit(0);
    28 }
  • 相关阅读:
    有关tensorflow一些问题
    一个完整openlayer的例子,包括marker,popup等
    OpenLayers中的Layer概念和实践--Openlayers调用WMS服务
    MapInfo格式转arggis格式
    arcgis for server 登陆manager失败解决办法
    1752:鸡兔同笼(2.1)
    1749:数字方格(2.1)
    08:石头剪刀布(1.6)
    c++中的243、251、250错误原因
    05:年龄与疾病(1.6)
  • 原文地址:https://www.cnblogs.com/zhiqli/p/3487638.html
Copyright © 2011-2022 走看看