receive a message from a queue


#include <mqueue.h>
int mq_receive( mqd_t mqdes, 
                char *msg_ptr, 
                size_t msg_len, 
                unsigned int *msg_prio );


The mq_receive() function is used to receive the oldest of the highest priority messages in the queue specified by mqdes. The priority of the message received is put in the location pointed to by msg_prio, the data itself in the location pointed to by msg_ptr, and the size received is returned.

If mq_receive() is called with a msg_len of anything other than the mq_msgsize of the specified queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't been set in the queue's mq_flags, then mq_receive() returns an error, and errno is set to EINVAL.

The mq_receive() call blocks if all the following occur:

If multiple mq_receive() calls are blocked on a single queue, then they're unblocked in FIFO order as messages arrive.

If msg_prio isn't NULL, then the location it references is used to store the priority of the message removed from the queue.

Calling read() with an file descriptor that represents a message queue is analogous to calling mq_receive() with a NULL msg_prio.


Upon successful completion, mq_receive() returns the size of the message removed from the queue specified. If the call fails, it returns -1 as the size, no message is removed from the queue, and errno is set.


O_NONBLOCK or MQ_NONBLOCK was set and there are no messages currently on the specified queue.
mqdes doesn't represent a valid queue open for reading.
This value indicates one of the following:
This value indicates one of the following:
The operation was interrupted by a signal.


POSIX 1003.4

Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes


In order to use the mq_... functions, you must:

See also:

errno, mq_close(), mq_getattr(), mq_notify(), mq_open(), mq_send(), mq_setattr(), mq_unlink(), read()

chapter on POSIX.4 message queues