如下代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <mqueue.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>#define MQ_DATA_FILE "/tmp/tmp_mq_ipc_file"int main(int argc, char **argv)
{mqd_t mq_list;struct mq_attr qu_attr;int flags = O_RDWR | O_NONBLOCK | O_CREAT | O_EXCL;mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;mq_list = mq_open(MQ_DATA_FILE, flags, mode, NULL);if (mq_list == -1){printf("create mq failed, errno:%d,%s\n", errno, strerror(errno));exit(EXIT_FAILURE);}printf("MQ creat succeed!\n");memset(&qu_attr, 0, sizeof(struct mq_attr));if (mq_getattr(mq_list, &qu_attr) == -1){printf("get mqueue attr failed,errno:%d,%s\n", errno, strerr