1msgget(2)                     System Calls Manual                    msgget(2)
2
3
4

NAME

6       msgget - get a System V message queue identifier
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/msg.h>
13
14       int msgget(key_t key, int msgflg);
15

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

STANDARDS

83       POSIX.1-2008.
84

HISTORY

86       POSIX.1-2001, SVr4.
87
88   Linux
89       Until Linux 2.3.20, Linux would return EIDRM for a msgget() on  a  mes‐
90       sage queue scheduled for deletion.
91

NOTES

93       IPC_PRIVATE isn't a flag field but a key_t type.  If this special value
94       is used for key, the system call ignores everything but the least  sig‐
95       nificant 9 bits of msgflg and creates a new message queue (on success).
96
97       The  following is a system limit on message queue resources affecting a
98       msgget() call:
99
100       MSGMNI System-wide limit on the number of message queues.  Before Linux
101              3.19,  the  default  value for this limit was calculated using a
102              formula based on available system memory.  Since Linux 3.19, the
103              default  value  is 32,000.  On Linux, this limit can be read and
104              modified via /proc/sys/kernel/msgmni.
105

BUGS

107       The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW would more
108       clearly show its function.
109

SEE ALSO

111       msgctl(2),  msgrcv(2),  msgsnd(2),  ftok(3),  capabilities(7), mq_over‐
112       view(7), sysvipc(7)
113
114
115
116Linux man-pages 6.04              2023-03-30                         msgget(2)
Impressum