1MSGGET(2)                  Linux Programmer's Manual                 MSGGET(2)
2
3
4

NAME

6       msgget - get a System V message queue identifier
7

SYNOPSIS

9       #include <sys/msg.h>
10
11       int msgget(key_t key, int msgflg);
12

DESCRIPTION

14       The  msgget() system call returns the System V message queue identifier
15       associated with the value of the key argument.  It may be  used  either
16       to  obtain  the  identifier of a previously created message queue (when
17       msgflg is zero and key does not have the value IPC_PRIVATE), or to cre‐
18       ate a new set.
19
20       A  new message queue is created if key has the value IPC_PRIVATE or key
21       isn't IPC_PRIVATE, no message queue with the given key key exists,  and
22       IPC_CREAT is specified in msgflg.
23
24       If msgflg specifies both IPC_CREAT and IPC_EXCL and a message queue al‐
25       ready exists for key, then msgget() fails with  errno  set  to  EEXIST.
26       (This  is  analogous  to the effect of the combination O_CREAT | O_EXCL
27       for open(2).)
28
29       Upon creation, the least significant bits of the argument msgflg define
30       the  permissions  of the message queue.  These permission bits have the
31       same format and semantics as the permissions specified for the mode ar‐
32       gument of open(2).  (The execute permissions are not used.)
33
34       If  a  new message queue is created, then its associated data structure
35       msqid_ds (see msgctl(2)) is initialized as follows:
36
37msg_perm.cuid and msg_perm.uid are set to the effective  user  ID  of
38         the calling process.
39
40msg_perm.cgid  and  msg_perm.gid are set to the effective group ID of
41         the calling process.
42
43       • The least significant 9 bits of msg_perm.mode are set  to  the  least
44         significant 9 bits of msgflg.
45
46msg_qnum,  msg_lspid,  msg_lrpid, msg_stime, and msg_rtime are set to
47         0.
48
49msg_ctime is set to the current time.
50
51msg_qbytes is set to the system limit MSGMNB.
52
53       If the message queue already exists the permissions are verified, and a
54       check is made to see if it is marked for destruction.
55

RETURN VALUE

57       On  success,  msgget() returns the message queue identifier (a nonnega‐
58       tive integer).  On failure, -1 is returned, and errno is set  to  indi‐
59       cate the error.
60

ERRORS

62       EACCES A message queue exists for key, but the calling process does not
63              have permission to access the  queue,  and  does  not  have  the
64              CAP_IPC_OWNER  capability in the user namespace that governs its
65              IPC namespace.
66
67       EEXIST IPC_CREAT and IPC_EXCL were specified in msgflg, but  a  message
68              queue already exists for key.
69
70       ENOENT No  message  queue  exists  for  key  and msgflg did not specify
71              IPC_CREAT.
72
73       ENOMEM A message queue has to be created but the system does  not  have
74              enough memory for the new data structure.
75
76       ENOSPC A  message  queue has to be created but the system limit for the
77              maximum number of message queues (MSGMNI) would be exceeded.
78

CONFORMING TO

80       POSIX.1-2001, POSIX.1-2008, SVr4.
81

NOTES

83       IPC_PRIVATE isn't a flag field but a key_t type.  If this special value
84       is  used for key, the system call ignores everything but the least sig‐
85       nificant 9 bits of msgflg and creates a new message queue (on success).
86
87       The following is a system limit on message queue resources affecting  a
88       msgget() call:
89
90       MSGMNI System-wide limit on the number of message queues.  Before Linux
91              3.19, the default value for this limit was  calculated  using  a
92              formula based on available system memory.  Since Linux 3.19, the
93              default value is 32,000.  On Linux, this limit can be  read  and
94              modified via /proc/sys/kernel/msgmni.
95
96   Linux notes
97       Until version 2.3.20, Linux would return EIDRM for a msgget() on a mes‐
98       sage queue scheduled for deletion.
99

BUGS

101       The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW would more
102       clearly show its function.
103

SEE ALSO

105       msgctl(2),  msgrcv(2),  msgsnd(2),  ftok(3),  capabilities(7), mq_over‐
106       view(7), sysvipc(7)
107

COLOPHON

109       This page is part of release 5.13 of the Linux  man-pages  project.   A
110       description  of  the project, information about reporting bugs, and the
111       latest    version    of    this    page,    can     be     found     at
112       https://www.kernel.org/doc/man-pages/.
113
114
115
116Linux                             2021-03-22                         MSGGET(2)
Impressum