1MSGGET(2)                  Linux Programmer's Manual                 MSGGET(2)
2
3
4

NAME

6       msgget - get a 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 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 initialised 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
62                  not  have  permission to access the queue, and does not have
63                  the 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
72                  have enough memory for the new data structure.
73
74       ENOSPC     A  message  queue has to be created but the system limit for
75                  the maximum number  of  message  queues  (MSGMNI)  would  be
76                  exceeded.
77

NOTES

79       IPC_PRIVATE isn't a flag field but a key_t type.  If this special value
80       is used for key, the system call ignores everything but the least  sig‐
81       nificant 9 bits of msgflg and creates a new message queue (on success).
82
83       The  following is a system limit on message queue resources affecting a
84       msgget() call:
85
86       MSGMNI     System wide maximum number of message queues: policy  depen‐
87                  dent  (on  Linux,  this  limit  can be read and modified via
88                  /proc/sys/kernel/msgmni).
89

BUGS

91       The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW would more
92       clearly show its function.
93

CONFORMING TO

95       SVr4, POSIX.1-2001.
96

LINUX NOTES

98       Until  version 2.3.20 Linux would return EIDRM for a msgget() on a mes‐
99       sage queue scheduled for deletion.
100

SEE ALSO

102       msgctl(2), msgrcv(2),  msgsnd(2),  ftok(3),  capabilities(7),  mq_over‐
103       view(7), svipc(7)
104
105
106
107Linux 2.6.6                       2004-05-27                         MSGGET(2)
Impressum