1MSGGET(2) Linux Programmer's Manual MSGGET(2)
2
3
4
6 msgget - get a System V message queue identifier
7
9 #include <sys/types.h>
10 #include <sys/ipc.h>
11 #include <sys/msg.h>
12
13 int msgget(key_t key, int msgflg);
14
16 The msgget() system call returns the System V message queue identifier
17 associated with the value of the key argument. A new message queue is
18 created if key has the value IPC_PRIVATE or key isn't IPC_PRIVATE, no
19 message queue with the given key key exists, and IPC_CREAT is specified
20 in msgflg.
21
22 If msgflg specifies both IPC_CREAT and IPC_EXCL and a message queue
23 already exists for key, then msgget() fails with errno set to EEXIST.
24 (This is analogous to the effect of the combination O_CREAT | O_EXCL
25 for open(2).)
26
27 Upon creation, the least significant bits of the argument msgflg define
28 the permissions of the message queue. These permission bits have the
29 same format and semantics as the permissions specified for the mode
30 argument of open(2). (The execute permissions are not used.)
31
32 If a new message queue is created, then its associated data structure
33 msqid_ds (see msgctl(2)) is initialized as follows:
34
35 msg_perm.cuid and msg_perm.uid are set to the effective user ID
36 of the calling process.
37
38 msg_perm.cgid and msg_perm.gid are set to the effective group ID
39 of the calling process.
40
41 The least significant 9 bits of msg_perm.mode are set to the
42 least significant 9 bits of msgflg.
43
44 msg_qnum, msg_lspid, msg_lrpid, msg_stime, and msg_rtime are set
45 to 0.
46
47 msg_ctime is set to the current time.
48
49 msg_qbytes is set to the system limit MSGMNB.
50
51 If the message queue already exists the permissions are verified, and a
52 check is made to see if it is marked for destruction.
53
55 If successful, the return value will be the message queue identifier (a
56 nonnegative integer), otherwise -1 with errno indicating the error.
57
59 On failure, errno is set to one of the following values:
60
61 EACCES A message queue exists for key, but the calling process does not
62 have permission to access the queue, and does not have the
63 CAP_IPC_OWNER capability in the user namespace that governs its
64 IPC namespace.
65
66 EEXIST IPC_CREAT and IPC_EXCL were specified in msgflg, but a message
67 queue already exists for key.
68
69 ENOENT No message queue exists for key and msgflg did not specify
70 IPC_CREAT.
71
72 ENOMEM A message queue has to be created but the system does not have
73 enough memory for the new data structure.
74
75 ENOSPC A message queue has to be created but the system limit for the
76 maximum number of message queues (MSGMNI) would be exceeded.
77
79 POSIX.1-2001, POSIX.1-2008, SVr4.
80
82 The inclusion of <sys/types.h> and <sys/ipc.h> isn't required on Linux
83 or by any version of POSIX. However, some old implementations required
84 the inclusion of these header files, and the SVID also documented their
85 inclusion. Applications intended to be portable to such old systems
86 may need to include these header files.
87
88 IPC_PRIVATE isn't a flag field but a key_t type. If this special value
89 is used for key, the system call ignores everything but the least sig‐
90 nificant 9 bits of msgflg and creates a new message queue (on success).
91
92 The following is a system limit on message queue resources affecting a
93 msgget() call:
94
95 MSGMNI System-wide limit on the number of message queues. Before Linux
96 3.19, the default value for this limit was calculated using a
97 formula based on available system memory. Since Linux 3.19, the
98 default value is 32,000. On Linux, this limit can be read and
99 modified via /proc/sys/kernel/msgmni.
100
101 Linux notes
102 Until version 2.3.20, Linux would return EIDRM for a msgget() on a mes‐
103 sage queue scheduled for deletion.
104
106 The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW would more
107 clearly show its function.
108
110 msgctl(2), msgrcv(2), msgsnd(2), ftok(3), capabilities(7), mq_over‐
111 view(7), svipc(7)
112
114 This page is part of release 4.15 of the Linux man-pages project. A
115 description of the project, information about reporting bugs, and the
116 latest version of this page, can be found at
117 https://www.kernel.org/doc/man-pages/.
118
119
120
121Linux 2017-09-15 MSGGET(2)