2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH MQ_RECEIVE 3 2014-06-03 "Linux" "Linux Programmer's Manual"
28 mq_receive, mq_timedreceive \- receive a message from a message queue
31 .B #include <mqueue.h>
33 .BI "ssize_t mq_receive(mqd_t " mqdes ", char *" msg_ptr ,
34 .BI " size_t " msg_len ", unsigned int *" msg_prio );
37 .B #include <mqueue.h>
39 .BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *" msg_ptr ,
40 .BI " size_t " msg_len ", unsigned int *" msg_prio ,
41 .BI " const struct timespec *" abs_timeout );
44 Link with \fI\-lrt\fP.
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
52 .BR mq_timedreceive ():
54 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
59 removes the oldest message with the highest priority from
60 the message queue referred to by the descriptor
62 and places it in the buffer pointed to by
66 argument specifies the size of the buffer pointed to by
68 this must be greater than or equal to the
70 attribute of the queue (see
74 is not NULL, then the buffer to which it points is used
75 to return the priority associated with the received message.
77 If the queue is empty, then, by default,
79 blocks until a message becomes available,
80 or the call is interrupted by a signal handler.
83 flag is enabled for the message queue description,
84 then the call instead fails immediately with the error
87 .BR mq_timedreceive ()
90 except that if the queue is empty and the
92 flag is not enabled for the message queue description, then
94 points to a structure which specifies a ceiling on the time for which
96 This ceiling is an absolute timeout in seconds and nanoseconds
97 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), and it is
98 specified in the following structure:
103 time_t tv_sec; /* seconds */
104 long tv_nsec; /* nanoseconds */
109 If no message is available,
110 and the timeout has already expired by the time of the call,
111 .BR mq_timedreceive ()
117 .BR mq_timedreceive ()
118 return the number of bytes in the received message;
119 on error, \-1 is returned, with
121 set to indicate the error.
125 The queue was empty, and the
127 flag was set for the message queue description referred to by
131 The descriptor specified in
136 The call was interrupted by a signal handler; see
140 The call would have blocked, and
142 was invalid, either because
144 was less than zero, or because
146 was less than zero or greater than 1000 million.
152 attribute of the message queue.
155 The call timed out before a message could be transferred.
157 .SS Multithreading (see pthreads(7))
161 .BR mq_timedreceive ()
162 functions are thread-safe.
167 .BR mq_timedreceive ()
168 is a system call, and
170 is a library function layered on top of that system call.