MSGGET(3POSIX)

โœจ MSGGET ๐Ÿ’ฌ (that's MSGGET(3POSIX) bestie, straight outta the POSIX Programmer's Manual ๐Ÿซถ)

okay so before we even get into it, let me just say: this page is part of the POSIX Programmer's Manual. ๐Ÿ’– That means the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for deets on Linux behavior if that's your vibe), or honestly? The interface might not even be implemented on Linux at all. ๐Ÿ™ˆ Not every system wants to play.


๐ŸŒธ PROLOG ๐ŸŒธ

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.

no cap, read that twice. it matters. ๐Ÿ’…

๐Ÿ‘‘ NAME ๐Ÿ‘‘

msgget โ€” get the XSI message queue identifier. that's it. that's the whole job. iconic behavior honestly. โœจ


๐Ÿ’… SYNOPSIS ๐Ÿ’…

#include <sys/msg.h>

int msgget(key_t key, int msgflg);

literally two things: a key, and some msgflg flags. slay. ๐ŸŽ€


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So the msgget() function operates on XSI message queues โ€” and if you wanna get specific, that's the Base Definitions volume of POSIX.1โ€2017, Section 3.226, Message Queue. ๐Ÿ“ฌ

Heads up bestie: it is unspecified whether this function interoperates with the realtime interprocess communication facilities defined in Section 2.8, Realtime. So like... don't assume. ๐Ÿซ 

The msgget() function shall return the message queue identifier associated with the argument key. ๐Ÿ”‘

A message queue identifier, an associated message queue, and a data structure (peep <sys/msg.h>) shall be created for the argument key if one of the following is true:

  • The argument key is equal to IPC_PRIVATE. ๐Ÿคซ
  • The argument key does not already have a message queue identifier associated with it, and (msgflg & IPC_CREAT) is non-zero.

๐ŸŽ€ Upon creation, the glow-up checklist ๐ŸŽ€

Once it's created, the data structure associated with the new message queue identifier shall be initialized like this, no exceptions:

  • msg_perm.cuid, msg_perm.uid, msg_perm.cgid, and msg_perm.gid shall be set to the effective user ID and effective group ID, respectively, of the calling process. ๐Ÿชช
  • The low-order 9 bits of msg_perm.mode shall be set to the low-order 9 bits of msgflg. ๐Ÿ”ข
  • msg_qnum, msg_lspid, msg_lrpid, msg_stime, and msg_rtime shall be set to 0. โญ fresh start energy
  • msg_ctime shall be set to the current time, as described in Section 2.7.1, IPC General Description. โฐ
  • msg_qbytes shall be set to the system limit. ๐Ÿ“

๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

Upon successful completion, msgget() shall return a non-negative integer, namely a message queue identifier. ๐Ÿฅณ

Otherwise, it shall return -1 and set errno to indicate the error. ๐Ÿ’€ (not the cute kind of ๐Ÿ’€)


๐Ÿ’œ ERRORS ๐Ÿ’œ

The msgget() function shall fail if:

  • EACCES โ€” A message queue identifier exists for the argument key, but operation permission as specified by the low-order 9 bits of msgflg would not be granted; see Section 2.7, XSI Interprocess Communication. ๐Ÿšซ
  • EEXIST โ€” A message queue identifier exists for the argument key but ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) is non-zero. ๐Ÿ˜ค it's literally already there bestie
  • ENOENT โ€” A message queue identifier does not exist for the argument key and (msgflg & IPC_CREAT) is 0. ๐Ÿซฅ nothing there, and you didn't ask to make one
  • ENOSPC โ€” A message queue identifier is to be created but the system-imposed limit on the maximum number of allowed message queue identifiers system-wide would be exceeded. ๐Ÿˆต full house, no more room

The following sections are informative. (translation: the actual rules are done, everything after this is vibes and context โœจ)


๐Ÿ™ˆ EXAMPLES ๐Ÿ™ˆ

None. ๐Ÿ˜ญ yeah. nothing. we move.


๐ŸŒˆ APPLICATION USAGE ๐ŸŒˆ

The POSIX Realtime Extension defines alternative interfaces for interprocess communication (IPC). ๐Ÿ“ก

Application developers who need to use IPC should design their applications so that modules using the IPC routines described in Section 2.7, XSI Interprocess Communication can be easily modified to use the alternative interfaces.

basically: write it so future-you can swap it out without a meltdown. future-proofing is main character energy. ๐Ÿ‘‘

๐Ÿงš RATIONALE ๐Ÿงš

None. ๐Ÿ’… the reasoning is implied, we guess.


โญ FUTURE DIRECTIONS โญ

None. ๐Ÿ”ฎ the future is blank and full of possibility (for this specific thing, at least).


๐Ÿ“ SEE ALSO ๐Ÿ“

  • Section 2.7, XSI Interprocess Communication
  • Section 2.8, Realtime
  • ftok()
  • mq_close()
  • mq_getattr()
  • mq_notify()
  • mq_open()
  • mq_receive()
  • mq_send()
  • mq_setattr()
  • mq_unlink()
  • msgctl()
  • msgrcv()
  • msgsnd()

The Base Definitions volume of POSIX.1โ€2017, Section 3.226, Message Queue, <sys_msg.h> ๐Ÿ“š


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 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 .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ๐Ÿ’…๐Ÿซถ

This one came from IEEE/The Open Group, 2017 โ€” so go give them their flowers ๐ŸŒธ because that's who wrote MSGGET(3POSIX), and that's the version-and-date tea at the very bottom of the page. bye pookie, go make some message queues ๐Ÿ’Œ

๐Ÿ“ฆ where this page comes from