Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Message Queue (mqueue.h), Invalid Argument Error, In C

I have not been able to create and open a message queue in C.

I tried with various arguments to mq_open() function yet nothing has come out of it.

I have checked some similar issues, but have not been able to get a solution.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am not sure what I am doing wrong.

I am getting a mq_open: Invalid argument error.

// Create the message queue
mqd_t mq;

// Open the message queue
mq = mq_open(argv[1], O_RDONLY | O_CREAT, 0666, NULL);
if (mq == (mqd_t)-1) {
       perror("mq_open");
       exit(EXIT_FAILURE);
}

I am arbitrarily giving it the name ‘a’.

>Solution :

I am arbitrarily giving it the name ‘a’.

That is an invalid name for a message queue. Such names must begin with a leading "/". This spelled out in the man page for mq_overview, which is referenced in the man page for mq_open:

Message queues are created and opened using mq_open(3); this
function returns a message queue descriptor (mqd_t), which is
used to refer to the open message queue in later calls. Each
message queue is identi‐ fied by a name of the form /somename;
that is, a null-terminated string of up to NAME_MAX (i.e., 255)
characters consisting of an initial slash, followed by one or
more characters, none of which are slashes. Two processes can
operate on the same queue by passing the same name to mq_open(3).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading