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 the O_NONBLOCK flag was set for the message queue description referred to by mqdes.
  • EBADF โ€” the descriptor specified in mqdes was invalid, or it wasn't opened for writing. rude.
  • EINTR โ€” the call was interrupted by a signal handler; peep signal(7).
  • EINVAL โ€” the call would have blocked, and abs_timeout was invalid โ€” either because tv_sec was less than zero, or because tv_nsec was less than zero or greater than 1000 million.
  • EMSGSIZE โ€” msg_len was greater than the mq_msgsize attribute 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms