1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH MQ_RECEIVE 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 mq_receive, mq_timedreceive \- receive a message from a message queue
30 .B #include <mqueue.h>
32 .BI "ssize_t mq_receive(mqd_t " mqdes ", char *" msg_ptr ,
33 .BI " size_t " msg_len ", unsigned int *" msg_prio );
36 .B #include <mqueue.h>
38 .BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *restrict " msg_ptr ,
39 .BI " size_t " msg_len ", unsigned int *restrict " msg_prio ,
40 .BI " const struct timespec *restrict " abs_timeout );
43 Link with \fI\-lrt\fP.
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
51 .BR mq_timedreceive ():
53 _POSIX_C_SOURCE >= 200112L
57 removes the oldest message with the highest priority from
58 the message queue referred to by the message queue descriptor
60 and places it in the buffer pointed to by
64 argument specifies the size of the buffer pointed to by
66 this must be greater than or equal to the
68 attribute of the queue (see
72 is not NULL, then the buffer to which it points is used
73 to return the priority associated with the received message.
75 If the queue is empty, then, by default,
77 blocks until a message becomes available,
78 or the call is interrupted by a signal handler.
81 flag is enabled for the message queue description,
82 then the call instead fails immediately with the error
85 .BR mq_timedreceive ()
88 except that if the queue is empty and the
90 flag is not enabled for the message queue description, then
92 points to a structure which specifies how long the call will block.
93 This value is an absolute timeout in seconds and nanoseconds
94 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC),
95 specified in the following structure:
100 time_t tv_sec; /* seconds */
101 long tv_nsec; /* nanoseconds */
106 If no message is available,
107 and the timeout has already expired by the time of the call,
108 .BR mq_timedreceive ()
114 .BR mq_timedreceive ()
115 return the number of bytes in the received message;
116 on error, \-1 is returned, with
118 set to indicate the error.
122 The queue was empty, and the
124 flag was set for the message queue description referred to by
128 The descriptor specified in
130 was invalid or not opened for reading.
133 The call was interrupted by a signal handler; see
137 The call would have blocked, and
139 was invalid, either because
141 was less than zero, or because
143 was less than zero or greater than 1000 million.
149 attribute of the message queue.
152 The call timed out before a message could be transferred.
154 For an explanation of the terms used in this section, see
162 Interface Attribute Value
165 .BR mq_timedreceive ()
166 T} Thread safety MT-Safe
172 POSIX.1-2001, POSIX.1-2008.
175 .BR mq_timedreceive ()
176 is a system call, and
178 is a library function layered on top of that system call.