23,121
社区成员
发帖
与我相关
我的任务
分享
If name begins with the slash character, then processes calling mq_open() with the same value of name shall refer to the same message queue object, as long as that name has not been removed. If name does not begin with the slash character, the effect is implementation-defined. The interpretation of slash characters other than the leading slash character in name is implementation-defined. If the name argument is not the name of an existing message queue and creation is not requested, mq_open() shall fail and return an error.
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
int main(void)
{
mqd_t mqd;
int oflag;
char name[PATH_MAX + 1];
oflag = O_CREAT | O_RDWR;
strcpy(name, "/mq_mymtom");
mqd = mq_open(name, oflag, FILE_MODE, NULL);
if ((mqd_t)-1 == mqd)
perror("mq_open()");
else
printf("mq_open(): success.\n");
strcpy(name, "mq_mymtom");
mqd = mq_open(name, oflag, FILE_MODE, NULL);
if ((mqd_t)-1 == mqd)
perror("mq_open()");
else
printf("mq_open(): success.\n");
return 0;
}