Posix消息队列的基本操作——获取消息属性

#include <unistd.h>
#include <mqueue.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    mqd_t   mqd;
    struct  mq_attr attr;

    if(argc != 2)
    {
        printf("usage: mqgetattr <name>");
    }
    mqd = mq_open(argv[1], O_RDONLY);
    
    mq_getattr(mqd, &attr);

    printf("max #msgs = %ld, max #bytes/msg = %ld, "
            "#currently on queue = % ld\n",
            attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);

    mq_close(mqd);

    exit(0);
}

你可能感兴趣的:(Posix消息队列的基本操作——获取消息属性)