mq_send(3)
๐ mq_send(3) โ send a message to a message queue
okay bestie, this is mq_send(3) and her slightly extra sister mq_timedsend(3), living in the library functions manual, and they're literally the way you yeet a message into a message queue. no cap.
๐ LIBRARY
Real-time library โ that's librt, link it with -lrt ๐
โจ SYNOPSIS โจ
#include <mqueue.h>
int mq_send(size_t msg_len;
mqd_t mqdes, const char msg_ptr[msg_len],
size_t msg_len, unsigned int msg_prio);
#include <time.h>
#include <mqueue.h>
int mq_timedsend(size_t msg_len;
mqd_t mqdes, const char msg_ptr[msg_len],
size_t msg_len, unsigned int msg_prio,
const struct timespec *abs_timeout);
๐ง Feature Test Macro Requirements for glibc
(peep feature_test_macros(7) for the full tea โ)
mq_timedsend():_POSIX_C_SOURCE >= 200112L
๐ธ DESCRIPTION ๐ธ
mq_send() takes the message that msg_ptr is pointing at and adds it to the message queue that the message queue descriptor mqdes refers to. the msg_len argument says how long the message msg_ptr points at is โ and this length must be less than or equal to the queue's mq_msgsize attribute. zero-length messages? allowed. iconic behavior, honestly.
the msg_prio argument is a nonnegative integer that sets the priority of this message. messages go on the queue in decreasing order of priority, and if two messages have the same priority, the newer one gets placed after the older ones with that same priority. for the full range of the message priority, go read mq_overview(7) ๐ซถ
if the message queue is already full (meaning the number of messages on the queue equals the queue's mq_maxmsg attribute), then by default mq_send() blocks until enough space frees up to let the message get queued โ or until the call gets interrupted by a signal handler. but if the O_NONBLOCK flag is enabled for the message queue description, then the call doesn't wait at all and instead fails immediately with the error EAGAIN. ๐
mq_timedsend() behaves just like mq_send(), except: if the queue is full and the O_NONBLOCK flag is not enabled for the message queue description, then abs_timeout points to a structure that specifies how long the call will block. that value is an absolute timeout in seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), written out in a timespec(3) structure. โฐ
and if the message queue is full and the timeout has already expired by the time of the call, mq_timedsend() returns immediately. no waiting around, periodt.
๐ RETURN VALUE ๐
on success, mq_send() and mq_timedsend() return zero โจ
on error, -1 is returned, and errno is set to say what went wrong. ๐ญ
๐ ERRORS ๐
EAGAINโ the queue was full, and theO_NONBLOCKflag was set for the message queue description referred to bymqdes.EBADFโ the descriptor specified inmqdeswas invalid, or it wasn't opened for writing. rude.EINTRโ the call was interrupted by a signal handler; peepsignal(7).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.EMSGSIZEโmsg_lenwas greater than themq_msgsizeattribute of the message queue.ETIMEDOUTโ the call timed out before a message could be transferred. the audacity.
๐ฅ ATTRIBUTES ๐ฅ
for an explanation of the terms used in this section, see attributes(7).
mq_send(),mq_timedsend()โ Thread safety:MT-Safe๐
๐ VERSIONS ๐
on Linux, mq_timedsend() is a system call, and mq_send() is a library function layered on top of that system call. so one's the main character and one's the main character's hype woman, iykyk.
โญ STANDARDS โญ
POSIX.1-2008.
๐ HISTORY ๐
POSIX.1-2001.
๐ SEE ALSO ๐
mq_close(3), mq_getattr(3), mq_notify(3), mq_open(3), mq_receive(3), mq_unlink(3), timespec(3), mq_overview(7), time(7)
okay that's the whole page bestie, go forth and queue your messages ๐
this was brought to you by Linux man-pages 6.20, dated 2026-02-08, and it's the mq_send(3) page โ slay, no notes. ๐ฆโจ
๐ฆ 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