MQ_CLOSE(2)

πŸ’– mq_close β€” bestie's guide to closing a message queue (REALTIME) πŸ’–

okay so this is a page from the System Calls Manual, and we're talking about mq_close πŸ’… lowkey one of the simplest syscalls you'll ever meet, but she still deserves her moment.


πŸ“š LIBRARY

POSIX Real-time Library β€” that's librt, link it with -lrt or she simply will not show up to the function party 🫢


✨ SYNOPSIS ✨

#include <mqueue.h>

int
mq_close(mqd_t mqdes);

that's it. that's the whole vibe. one descriptor in, vibes out πŸ’–


🌸 DESCRIPTION 🌸

so mq_close() is the syscall that removes the association between the message queue descriptor, mqdes, and its message queue. like, she's breaking up with the queue. amicably. no drama. πŸ’”βœ¨

⚠️ ok bestie this part matters: the results of using this message queue descriptor after a successful return from this mq_close(), and until the return of this message queue descriptor from a subsequent mq_open(), are UNDEFINED. not "kinda weird", not "probably fine" β€” undefined. do not touch her after the breakup. it's giving cursed energy πŸ’€

now, if the process has successfully attached a notification request to the message queue via this mqdes, then that attachment will be removed, and the message queue becomes available for another process to attach for notification. so like, the queue isn't sad and lonely β€” she's free to be claimed by someone new. slay for her honestly πŸ‘‘πŸ¦‹


πŸŽ€ RETURN VALUES πŸŽ€

  • on success β†’ the value 0 comes back. perfect. immaculate. no notes ✨
  • otherwise β†’ the value -1 comes back, and the global variable errno is set to tell you what went wrong πŸ™ˆ

πŸ’… ERRORS πŸ’…

mq_close() will fail if:

  • [EBADF] β€” the mqdes argument is not a valid message queue descriptor. basically you handed her a fake ID and she noticed. not the move, bestie 😭

πŸ”₯ SEE ALSO πŸ”₯


🌈 STANDARDS 🌈

mq_close() conforms to IEEE Std 1003.1-2004 (β€œPOSIX.1”). certified. official. she passed the vibe check βœ…


🧚 HISTORY 🧚

Support for POSIX message queues first appeared in FreeBSD 7.0. so she's been iconic since way back, we love a veteran πŸ’œ


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. In the event of 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.


and that's the whole page, bestie!! πŸŽ€ this Debian edition dropped November 29, 2005 and yes it's still serving. mwah πŸ’‹πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from