Search code examples

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.

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) {

I am arbitrarily giving it the name 'a'.


  • 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).