MQ_GETATTR(2)

πŸ’– mq_getattr β€” bestie edition πŸ’–

okay so you found the manpage for mq_getattr(2) β€” that's the system calls manual section, and it's all about the POSIX realtime message queue vibe. let's get into it πŸŽ€


✨ NAME ✨

mq_getattr β€” get message queue attributes (REALTIME)

πŸ“š LIBRARY πŸ“š

POSIX Real-time Library (librt, -lrt)

like, you gotta link it, bestie. -lrt. don't forget or it's giving undefined reference 😭


🌸 SYNOPSIS 🌸

#include <mqueue.h>

int
mq_getattr(mqd_t mqdes, struct mq_attr *mqstat);

πŸ’… DESCRIPTION πŸ’…

so the mq_getattr() system call grabs status info and attributes for two things at once, lowkey:

  • the message queue itself
  • the open message queue description that's chillin' with the message queue descriptor

the mqdes argument is your message queue descriptor. that's the one.

and the results? they get handed back in the mq_attr structure that mqstat points at. iconic.

on return, these members carry the values tied to the open message queue description β€” as they were set when the queue was opened, and as modified by any mq_setattr() calls that happened after:

  • mq_flags

and these attributes of the message queue come back exactly as they were set at message queue creation:

  • mq_maxmsg
  • mq_msgsize

also, on return, this member inside the mq_attr structure that mqstat points at gets set to the current state of the message queue:

  • mq_curmsgs β€” the number of messages currently on the queue.

so basically one call, three different flavours of info. main character energy honestly πŸ‘‘


πŸ”₯ RETURN VALUES πŸ”₯

slayed successfully? you get 0 back. periodt.

anything else and you get -1, plus the global variable errno gets set to tell you what went wrong. so check errno, bestie, it's literally right there 🫢


πŸ’€ ERRORS πŸ’€

the mq_getattr() system call will fail if:

  • [EBADF] β€” the mqdes argument is not a valid message queue descriptor.

that's the whole list. just the one. if your descriptor's fake, it's over 🚫


πŸ‘€ SEE ALSO πŸ‘€

go read those next, they're all in the same little friend group πŸ¦‹


⭐ STANDARDS ⭐

the mq_getattr() system call conforms to IEEE Std 1003.1-2004 (β€œPOSIX.1”). certified, no cap.


🌈 HISTORY 🌈

support for POSIX message queues first appeared in FreeBSD 7.0. vintage, but make it realtime πŸ’œ


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. if there's ever any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html.

like, the IEEE said it first, we're just quoting the queen πŸ’–


and that's the whole page!! this one's from Debian, dated February 21, 2014 β€” mwah, go check your queue attributes bestie, ily πŸŒΈβœ¨πŸŽ€

πŸ“¦ where this page comes from