免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 11281 | 回复: 9
打印 上一主题 下一主题

mq_open的参数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-24 15:28 |只看该作者 |倒序浏览
代码大体如下:
int main(...)
{
    ...
    mqd = mq_open(MSGQOBJ, O_RDWR | O_CREAT, FILE_MODE, NULL);
    if(mqd == -1)
    {
        perror("mq_open");
        exit(1);
    }
   
    ...
   
    mq_close(mqd);
    mq_unlink(MSGQOBJ);

    exit(0);
}

问题在:
mq_open(MSGQOBJ, O_RDWR | O_CREAT, FILE_MODE, NULL);
编译后,能通过,也能正常执行。

但是如果把第四个参数由NULL改为attr,重新编译的时候就会报:
mq_open:invalid argument

论坛徽章:
0
2 [报告]
发表于 2008-04-24 15:32 |只看该作者
在mq_open之前,会对attr初始化,如下:
attr.mq_flags = 0;
attr.mq_maxmsg = 31;
attr.mq_msgsize = 1024;

各位帮帮忙。

论坛徽章:
0
3 [报告]
发表于 2008-04-24 16:15 |只看该作者
貌似我问的问题很弱智哦。

论坛徽章:
0
4 [报告]
发表于 2008-04-24 16:30 |只看该作者
是不是传&attr

论坛徽章:
0
5 [报告]
发表于 2008-04-24 16:56 |只看该作者
传的就是&attr.上边没写清楚

论坛徽章:
0
6 [报告]
发表于 2008-11-23 09:51 |只看该作者
用mq_open()后函数返回mqd_t - 1,而不是-1

我运行 的时候,好像也遇到楼主的问题。
我用linux内核2.27.1编译通过,但不能运行,运行提示"permission deny"
用freebsd7.0编译也通过,但也还是不能运行,提示"illegal instruction "最后产生core文件,产生信号sigill

我现在还搞不明白是怎么回事

论坛徽章:
0
7 [报告]
发表于 2008-11-23 09:57 |只看该作者
上面漏了个括号(mqd_t) -1才对

论坛徽章:
0
8 [报告]
发表于 2008-11-23 10:35 |只看该作者
解决了,楼主请看这个帖子,这可能对你有用!
http://bbs.chinaunix.net/viewthread.php?tid=1017072

论坛徽章:
0
9 [报告]
发表于 2009-09-04 11:11 |只看该作者
这个问题该如解决,楼上的解决方案,引用的另外一贴。和这个不是同一个问题。

论坛徽章:
0
10 [报告]
发表于 2009-09-04 15:40 |只看该作者
与Posix message queue有关的attr有一定的系统上限,是你的参数出了该限制。


/proc interfaces
       The  following  interfaces  can  be  used to limit the amount of kernel memory consumed by POSIX message
       queues:

       /proc/sys/fs/mqueue/msg_max
              This file can be used to view and change the ceiling value for the maximum number of messages  in
              a  queue.  This value acts as a ceiling on the attr->mq_maxmsg argument given to mq_open(3).  The
              default   and   minimum   value   for   msg_max   is   10;   the   upper   limit   is   HARD_MAX:
              (131072 / sizeof(void *))  (32768  on  Linux/86).  This limit is ignored for privileged processes
              (CAP_SYS_RESOURCE), but the HARD_MAX ceiling is nevertheless imposed.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP