#include <stdio.h> #include <fcntl.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <mqueue.h> struct mq_attr attr; const int maxline=4096; int main(int argc, char **argv) { int c, flags; mqd_t mqd; char errbuff[maxline]; flags=O_RDWR | O_CREAT; while((c=getopt(argc, argv, "em:z:"))!=-1) { switch(c) { case 'e': flags|=O_EXCL; break; case 'm': attr.mq_maxmsg=atol(optarg); break; case 'z': attr.mq_msgsize=atol(optarg); break; } } if(optind != argc-1) { fprintf(stderr, "mqcreate [-e] [ -m maxmsg -z msgsize ] <name>\n"); exit(-1); } if((attr.mq_maxmsg!=0&&attr.mq_msgsize==0) || (attr.mq_maxmsg==0&&attr.mq_msgsize!=0)) { fprintf(stderr, "must specify both -m maxmsg -z msgsize\n"); exit(-1); } if((mqd=mq_open(argv[optind], flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, (attr.mq_maxmsg!=0) ? &attr:NULL))<0) { strerror_r(errno, errbuff, maxline); fprintf(stderr, "mq_open error: %s\n", errbuff); exit(-1); } mq_close(mqd); exit(0); }
标签:attr,msgsize,队列,创建,int,mq,消息,include,maxmsg From: https://www.cnblogs.com/donggongdechen/p/16771763.html