1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH MQ_RECEIVE 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
7 mq_receive, mq_timedreceive \- receive a message from a message queue
10 .RI ( librt ", " \-lrt )
13 .B #include <mqueue.h>
15 .BI "ssize_t mq_receive(mqd_t " mqdes ", char *" msg_ptr ,
16 .BI " size_t " msg_len ", unsigned int *" msg_prio );
19 .B #include <mqueue.h>
21 .BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *restrict " msg_ptr ,
22 .BI " size_t " msg_len ", unsigned int *restrict " msg_prio ,
23 .BI " const struct timespec *restrict " abs_timeout );
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
32 .BR mq_timedreceive ():
34 _POSIX_C_SOURCE >= 200112L
38 removes the oldest message with the highest priority from
39 the message queue referred to by the message queue descriptor
41 and places it in the buffer pointed to by
45 argument specifies the size of the buffer pointed to by
47 this must be greater than or equal to the
49 attribute of the queue (see
53 is not NULL, then the buffer to which it points is used
54 to return the priority associated with the received message.
56 If the queue is empty, then, by default,
58 blocks until a message becomes available,
59 or the call is interrupted by a signal handler.
62 flag is enabled for the message queue description,
63 then the call instead fails immediately with the error
66 .BR mq_timedreceive ()
69 except that if the queue is empty and the
71 flag is not enabled for the message queue description, then
73 points to a structure which specifies how long the call will block.
74 This value is an absolute timeout in seconds and nanoseconds
75 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC),
80 If no message is available,
81 and the timeout has already expired by the time of the call,
82 .BR mq_timedreceive ()
88 .BR mq_timedreceive ()
89 return the number of bytes in the received message;
90 on error, \-1 is returned, with
92 set to indicate the error.
96 The queue was empty, and the
98 flag was set for the message queue description referred to by
102 The descriptor specified in
104 was invalid or not opened for reading.
107 The call was interrupted by a signal handler; see
111 The call would have blocked, and
113 was invalid, either because
115 was less than zero, or because
117 was less than zero or greater than 1000 million.
123 attribute of the message queue.
126 The call timed out before a message could be transferred.
128 For an explanation of the terms used in this section, see
136 Interface Attribute Value
139 .BR mq_timedreceive ()
140 T} Thread safety MT-Safe
146 POSIX.1-2001, POSIX.1-2008.
149 .BR mq_timedreceive ()
150 is a system call, and
152 is a library function layered on top of that system call.