1MSGGET(2) Linux Programmer's Manual MSGGET(2)
2
3
4
6 msgget - get a 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 message queue identifier associ‐
17 ated with the value of the key argument. A new message queue is cre‐
18 ated if key has the value IPC_PRIVATE or key isn't IPC_PRIVATE, no mes‐
19 sage queue with the given key key exists, and IPC_CREAT is specified in
20 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.
64
65 EEXIST A message queue exists for key and msgflg specified both
66 IPC_CREAT and IPC_EXCL.
67
68 ENOENT No message queue exists for key and msgflg did not specify
69 IPC_CREAT.
70
71 ENOMEM A message queue has to be created but the system does not have
72 enough memory for the new data structure.
73
74 ENOSPC A message queue has to be created but the system limit for the
75 maximum number of message queues (MSGMNI) would be exceeded.
76
78 SVr4, POSIX.1-2001.
79
81 IPC_PRIVATE isn't a flag field but a key_t type. If this special value
82 is used for key, the system call ignores everything but the least sig‐
83 nificant 9 bits of msgflg and creates a new message queue (on success).
84
85 The following is a system limit on message queue resources affecting a
86 msgget() call:
87
88 MSGMNI System wide maximum number of message queues: policy dependent
89 (on Linux, this limit can be read and modified via
90 /proc/sys/kernel/msgmni).
91
92 Linux Notes
93 Until version 2.3.20 Linux would return EIDRM for a msgget() on a mes‐
94 sage queue scheduled for deletion.
95
97 The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW would more
98 clearly show its function.
99
101 msgctl(2), msgrcv(2), msgsnd(2), ftok(3), capabilities(7), mq_over‐
102 view(7), svipc(7)
103
105 This page is part of release 3.25 of the Linux man-pages project. A
106 description of the project, and information about reporting bugs, can
107 be found at http://www.kernel.org/doc/man-pages/.
108
109
110
111Linux 2004-05-27 MSGGET(2)