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.  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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

78       SVr4, POSIX.1-2001.
79

NOTES

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

BUGS

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

SEE ALSO

107       msgctl(2),  msgrcv(2),  msgsnd(2),  ftok(3),  capabilities(7), mq_over‐
108       view(7), svipc(7)
109

COLOPHON

111       This page is part of release 3.53 of the Linux  man-pages  project.   A
112       description  of  the project, and information about reporting bugs, can
113       be found at http://www.kernel.org/doc/man-pages/.
114
115
116
117Linux                             2012-05-31                         MSGGET(2)
Impressum