MSGGET(2)
๐ฌ MSGGET(2) โ get message queue ๐ฌ
okay bestie, welcome to the msggot... no wait, msgget page ๐ it's a System Calls Manual entry, and it is exactly the kind of thing you need in your life if you're out here doing inter-process communication like a boss. let's get into it ๐ซถ
โจ NAME โจ
msgget โ get a message queue, babes ๐
๐ LIBRARY ๐
Standard C Library (libc, -lc) ๐
๐ธ SYNOPSIS ๐ธ
#include <sys/msg.h>
int
msgget(key_t key, int msgflg);
๐ฆ DESCRIPTION ๐ฆ
so, the msgget() function returns the message queue identifier that's associated with key. and what even is a message queue identifier? it's a unique integer, and it's greater than zero, periodt ๐ฏ
here's the tea โ โ a message queue gets created if EITHER:
keyis equal toIPC_PRIVATE, ORkeydoesn't have a message queue identifier associated with it and theIPC_CREATbit is set inmsgflg
not me pointing out that you literally need theIPC_CREATbit if you want a fresh queue and the key isn'tIPC_PRIVATE. that's just how it is, no cap.
if a brand new message queue gets created, the data structure that's associated with it โ that's the msqid_ds structure, see msgctl(2) โ gets initialized like this ๐
msg_perm.cuidandmsg_perm.uidare set to the effective uid of the calling process ๐msg_perm.gidandmsg_perm.cgidare set to the effective gid of the calling process ๐msg_perm.modeis set to the lower 9 bits ofmsgflg, which are set by ORing these constants together:0400โ Read access for user ๐0200โ Write access for user โ๏ธ0040โ Read access for group ๐0020โ Write access for group โ๏ธ0004โ Read access for other ๐0002โ Write access for other โ๏ธ
msg_cbytes,msg_qnum,msg_lspid,msg_lrpid,msg_rtime, andmsg_stimeare all set to 0 ๐ซง (yes, all of them, they start from scratch, we love a clean slate)msg_qbytesis set to the system wide maximum value for the number of bytes in a queue โ that'sMSGMNB๐งฎmsg_ctimeis set to the current time โฐ
๐ RETURN VALUES ๐
if everything goes slay, a positive message queue identifier comes back at you ๐
otherwise? you get -1 back, and the global variable errno gets set to indicate the error ๐ญ (we hate to see it, but at least it tells you why)
๐ ERRORS ๐
- [EACCES] โ a message queue is already associated with
keyand the caller has no permission to access it ๐ - [EEXIST] โ both
IPC_CREATandIPC_EXCLare set inmsgflg, and a message queue is already associated withkey๐ค - [ENOSPC] โ a new message queue could not be created because the system limit for the number of message queues has been reached ๐ฅ
- [ENOENT] โ
IPC_CREATwas not set inmsgflgand no message queue associated withkeywas found ๐
๐ SEE ALSO ๐
msgctl(2), msgrcv(2), msgsnd(2) โ go read those next, bestie, they're the whole friend group ๐ซถ
๐ HISTORY ๐
Message queues appeared in the first release of AT&T System V UNIX โญ like... iconic behavior honestly, they've been around forever and they still ate ๐
and that's the whole page, my love ๐ this one's from the Debian fam, dated March 4, 2018 ๐ go make some queues, and don't forget to clean up after yourself, iykyk ๐ โจ
๐ฆ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1995 Frank van der Linden
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms