mq_receive(3)
π mq_receive(3) β like, the manual page for mq_receive, mq_timedreceive π
okay bestie, this is a Library Functions Manual page, and it's literally about two little functions that go grab a message off a message queue for you. no cap, it's giving very "i'm the one who fetches the mail" energy π«Ά
πΈ NAME πΈ
mq_receive, mq_timedreceive β receive a message from a message queue
so basically: get a message out of a message queue. that's the whole vibe β¨
π LIBRARY π
Real-time library (librt, link it with -lrt)
yes queen, you gotta link the real-time library. don't forget -lrt or the linker will simply not know her π
β¨ SYNOPSIS β¨
#include <mqueue.h>
ssize_t mq_receive(size_t msg_len;
mqd_t mqdes, char msg_ptr[msg_len],
size_t msg_len, unsigned int *msg_prio);
#include <time.h>
#include <mqueue.h>
ssize_t mq_timedreceive(size_t msg_len;
mqd_t mqdes, char *restrict msg_ptr[msg_len],
size_t msg_len, unsigned int *restrict msg_prio,
const struct timespec *restrict abs_timeout);
Feature Test Macro Requirements for glibc (if you wanna know what that even means, go read feature_test_macros(7)):
mq_timedreceive():
_POSIX_C_SOURCE >= 200112L
π DESCRIPTION π
mq_receive() removes the oldest message with the highest priority from the message queue referred to by the message queue descriptor mqdes, and places it in the buffer pointed to by msg_ptr. main character message selection, honestly β oldest and highest priority, periodt π
the msg_len argument specifies the size of the buffer pointed to by msg_ptr; this must be greater than or equal to the mq_msgsize attribute of the queue (peep mq_getattr(3) if you wanna check what that attribute is). so no, you can't bring a tiny little buffer to a big message party π
if msg_prio is not NULL, then the buffer to which it points is used to return the priority associated with the received message. free priority info, we love that for you β
if the queue is empty, then, by default, mq_receive() blocks until a message becomes available, or the call is interrupted by a signal handler. she will wait. patiently. forever if she has to π§
if the O_NONBLOCK flag is enabled for the message queue description, then the call instead fails immediately with the error EAGAIN. no waiting, no patience, just vibes and an error code π
mq_timedreceive() behaves just like mq_receive(), except that if the queue is empty and the O_NONBLOCK flag is not enabled for the message queue description, then abs_timeout points to a structure which specifies how long the call will block. this value is an absolute timeout in seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), specified in a timespec(3) structure. absolute, bestie. not "how long from now" β "what time on the clock." iykyk β°
if no message is available, and the timeout has already expired by the time of the call, mq_timedreceive() returns immediately. she's not even gonna pretend to wait for you π₯
π RETURN VALUE π
on success, mq_receive() and mq_timedreceive() return the number of bytes in the received message. slay, we got bytes π¦
on error, -1 is returned, with errno set to indicate the error. classic. check your errno, bestie π
π ERRORS π
EAGAINβ the queue was empty, and theO_NONBLOCKflag was set for the message queue description referred to bymqdes. nothing to read and you told her not to wait π«EBADFβ the descriptor specified inmqdeswas invalid or not opened for reading. girl, that descriptor is not it πEINTRβ the call was interrupted by a signal handler; seesignal(7). a signal literally walked in mid-conversation βEINVALβ the call would have blocked, andabs_timeoutwas invalid, either becausetv_secwas less than zero, or becausetv_nsecwas less than zero or greater than 1000 million. your timeout was giving nonsense π€EMSGSIZEβmsg_lenwas less than themq_msgsizeattribute of the message queue. buffer too smol. it's giving "i can't fit" πETIMEDOUTβ the call timed out before a message could be transferred. you waited, nothing came, time's up π
π ATTRIBUTES π
for an explanation of the terms used in this section, go see attributes(7).
| (as bullets, because we're cute) |
- Interface:
mq_receive(),mq_timedreceive() - Attribute: Thread safety
- Value:
MT-Safe
yes bestie, MT-Safe β she's thread safe, she can hang with all your threads at once π
β VERSIONS β
on Linux, mq_timedreceive() is a system call, and mq_receive() is a library function layered on top of that system call. so one of them is talking straight to the kernel and the other one is her little glibc representative π
πΈ STANDARDS πΈ
POSIX.1-2008.
π HISTORY π
POSIX.1-2001.
she's been around. vintage icon.
π¦ SEE ALSO π¦
mq_close(3), mq_getattr(3), mq_notify(3), mq_open(3), mq_send(3), mq_unlink(3), timespec(3), mq_overview(7), time(7)
the whole mq friend group, honestly. go say hi π«Ά
ok so that's the page!! this one comes from Linux man-pages 6.20, dated 2026-02-08, and it's filed under mq_receive(3) in the Library Functions Manual. go forth and receive your messages, bestie πβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2006, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms