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/types.h>
10       #include <sys/ipc.h>
11       #include <sys/msg.h>
12
13       int msgget(key_t key, int msgflg);
14

DESCRIPTION

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

RETURN VALUE

59       If successful, the return value will be the message queue identifier (a
60       nonnegative integer), otherwise -1 with errno indicating the error.
61

ERRORS

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

CONFORMING TO

83       POSIX.1-2001, POSIX.1-2008, SVr4.
84

NOTES

86       The  inclusion of <sys/types.h> and <sys/ipc.h> isn't required on Linux
87       or by any version of POSIX.  However, some old implementations required
88       the inclusion of these header files, and the SVID also documented their
89       inclusion.  Applications intended to be portable to  such  old  systems
90       may need to include these header files.
91
92       IPC_PRIVATE isn't a flag field but a key_t type.  If this special value
93       is used for key, the system call ignores everything but the least  sig‐
94       nificant 9 bits of msgflg and creates a new message queue (on success).
95
96       The  following is a system limit on message queue resources affecting a
97       msgget() call:
98
99       MSGMNI System-wide limit on the number of message queues.  Before Linux
100              3.19,  the  default  value for this limit was calculated using a
101              formula based on available system memory.  Since Linux 3.19, the
102              default  value  is 32,000.  On Linux, this limit can be read and
103              modified via /proc/sys/kernel/msgmni.
104
105   Linux notes
106       Until version 2.3.20, Linux would return EIDRM for a msgget() on a mes‐
107       sage queue scheduled for deletion.
108

BUGS

110       The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW would more
111       clearly show its function.
112

SEE ALSO

114       msgctl(2), msgrcv(2),  msgsnd(2),  ftok(3),  capabilities(7),  mq_over‐
115       view(7), sysvipc(7)
116

COLOPHON

118       This  page  is  part of release 5.04 of the Linux man-pages project.  A
119       description of the project, information about reporting bugs,  and  the
120       latest     version     of     this    page,    can    be    found    at
121       https://www.kernel.org/doc/man-pages/.
122
123
124
125Linux                             2019-08-02                         MSGGET(2)
Impressum