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
keyis equal toIPC_PRIVATE. ๐คซ - The argument
keydoes 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, andmsg_perm.gidshall be set to the effective user ID and effective group ID, respectively, of the calling process. ๐ชช- The low-order 9 bits of
msg_perm.modeshall be set to the low-order 9 bits ofmsgflg. ๐ข msg_qnum,msg_lspid,msg_lrpid,msg_stime, andmsg_rtimeshall be set to0. โญ fresh start energymsg_ctimeshall be set to the current time, as described in Section 2.7.1, IPC General Description. โฐmsg_qbytesshall 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 argumentkey, but operation permission as specified by the low-order 9 bits ofmsgflgwould not be granted; see Section 2.7, XSI Interprocess Communication. ๐ซEEXISTโ A message queue identifier exists for the argumentkeybut((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL))is non-zero. ๐ค it's literally already there bestieENOENTโ A message queue identifier does not exist for the argumentkeyand(msgflg & IPC_CREAT)is0. ๐ซฅ nothing there, and you didn't ask to make oneENOSPCโ 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> ๐
๐ COPYRIGHT ๐
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
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms