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

NAME

6       msgctl - System V message control operations
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/ipc.h>
11       #include <sys/msg.h>
12
13       int msgctl(int msqid, int cmd, struct msqid_ds *buf);
14

DESCRIPTION

16       msgctl()  performs  the  control operation specified by cmd on the Sys‐
17       tem V message queue with identifier msqid.
18
19       The msqid_ds data structure is defined in <sys/msg.h> as follows:
20
21           struct msqid_ds {
22               struct ipc_perm msg_perm;     /* Ownership and permissions */
23               time_t          msg_stime;    /* Time of last msgsnd(2) */
24               time_t          msg_rtime;    /* Time of last msgrcv(2) */
25               time_t          msg_ctime;    /* Time of last change */
26               unsigned long   __msg_cbytes; /* Current number of bytes in
27                                                queue (nonstandard) */
28               msgqnum_t       msg_qnum;     /* Current number of messages
29                                                in queue */
30               msglen_t        msg_qbytes;   /* Maximum number of bytes
31                                                allowed in queue */
32               pid_t           msg_lspid;    /* PID of last msgsnd(2) */
33               pid_t           msg_lrpid;    /* PID of last msgrcv(2) */
34           };
35
36       The ipc_perm structure is defined as follows  (the  highlighted  fields
37       are settable using IPC_SET):
38
39           struct ipc_perm {
40               key_t          __key;       /* Key supplied to msgget(2) */
41               uid_t          uid;         /* Effective UID of owner */
42               gid_t          gid;         /* Effective GID of owner */
43               uid_t          cuid;        /* Effective UID of creator */
44               gid_t          cgid;        /* Effective GID of creator */
45               unsigned short mode;        /* Permissions */
46               unsigned short __seq;       /* Sequence number */
47           };
48
49       Valid values for cmd are:
50
51       IPC_STAT
52              Copy  information from the kernel data structure associated with
53              msqid into the msqid_ds structure pointed to by buf.  The caller
54              must have read permission on the message queue.
55
56       IPC_SET
57              Write  the  values  of  some  members  of the msqid_ds structure
58              pointed to by buf to the kernel data structure  associated  with
59              this  message  queue,  updating  also its msg_ctime member.  The
60              following members of  the  structure  are  updated:  msg_qbytes,
61              msg_perm.uid,  msg_perm.gid,  and  (the least significant 9 bits
62              of) msg_perm.mode.  The effective UID  of  the  calling  process
63              must  match  the owner (msg_perm.uid) or creator (msg_perm.cuid)
64              of the message queue, or the caller must be privileged.   Appro‐
65              priate  privilege  (Linux:  the  CAP_SYS_RESOURCE capability) is
66              required to raise the msg_qbytes value beyond the system parame‐
67              ter MSGMNB.
68
69       IPC_RMID
70              Immediately  remove  the  message  queue,  awakening all waiting
71              reader and writer processes (with an error return and errno  set
72              to EIDRM).  The calling process must have appropriate privileges
73              or its effective user ID must be either that of the  creator  or
74              owner  of  the message queue.  The third argument to msgctl() is
75              ignored in this case.
76
77       IPC_INFO (Linux-specific)
78              Return information about system-wide message  queue  limits  and
79              parameters  in  the structure pointed to by buf.  This structure
80              is of type msginfo  (thus,  a  cast  is  required),  defined  in
81              <sys/msg.h> if the _GNU_SOURCE feature test macro is defined:
82
83                  struct msginfo {
84                      int msgpool; /* Size in kibibytes of buffer pool
85                                      used to hold message data;
86                                      unused within kernel */
87                      int msgmap;  /* Maximum number of entries in message
88                                      map; unused within kernel */
89                      int msgmax;  /* Maximum number of bytes that can be
90                                      written in a single message */
91                      int msgmnb;  /* Maximum number of bytes that can be
92                                      written to queue; used to initialize
93                                      msg_qbytes during queue creation
94                                      (msgget(2)) */
95                      int msgmni;  /* Maximum number of message queues */
96                      int msgssz;  /* Message segment size;
97                                      unused within kernel */
98                      int msgtql;  /* Maximum number of messages on all queues
99                                      in system; unused within kernel */
100                      unsigned short int msgseg;
101                                   /* Maximum number of segments;
102                                      unused within kernel */
103                  };
104
105              The msgmni, msgmax, and msgmnb settings can be changed via /proc
106              files of the same name; see proc(5) for details.
107
108       MSG_INFO (Linux-specific)
109              Return a msginfo structure containing the  same  information  as
110              for IPC_INFO, except that the following fields are returned with
111              information about system resources consumed by  message  queues:
112              the msgpool field returns the number of message queues that cur‐
113              rently exist on the system; the msgmap field returns  the  total
114              number  of  messages in all queues on the system; and the msgtql
115              field returns the total number of bytes in all messages  in  all
116              queues on the system.
117
118       MSG_STAT (Linux-specific)
119              Return a msqid_ds structure as for IPC_STAT.  However, the msqid
120              argument is not a queue identifier, but instead  an  index  into
121              the kernel's internal array that maintains information about all
122              message queues on the system.
123
124       MSG_STAT_ANY (Linux-specific, since Linux 4.17)
125              Return  a  msqid_ds  structure  as   for   MSG_STAT.    However,
126              msg_perm.mode  is  not checked for read access for msqid meaning
127              that any user can employ this operation (just as  any  user  may
128              read /proc/sysvipc/msg to obtain the same information).
129

RETURN VALUE

131       On  success,  IPC_STAT,  IPC_SET,  and IPC_RMID return 0.  A successful
132       IPC_INFO or MSG_INFO operation returns the index of  the  highest  used
133       entry  in  the  kernel's internal array recording information about all
134       message queues.  (This information can be used with  repeated  MSG_STAT
135       or  MSG_STAT_ANY  operations  to obtain information about all queues on
136       the system.)  A successful MSG_STAT or MSG_STAT_ANY  operation  returns
137       the identifier of the queue whose index was given in msqid.
138
139       On error, -1 is returned with errno indicating the error.
140

ERRORS

142       On failure, errno is set to one of the following:
143
144       EACCES The argument cmd is equal to IPC_STAT or MSG_STAT, but the call‐
145              ing process does not have read permission on the  message  queue
146              msqid,  and  does  not  have the CAP_IPC_OWNER capability in the
147              user namespace that governs its IPC namespace.
148
149       EFAULT The argument cmd has the value  IPC_SET  or  IPC_STAT,  but  the
150              address pointed to by buf isn't accessible.
151
152       EIDRM  The message queue was removed.
153
154       EINVAL Invalid  value  for cmd or msqid.  Or: for a MSG_STAT operation,
155              the index value specified in msqid referred  to  an  array  slot
156              that is currently unused.
157
158       EPERM  The  argument  cmd  has  the  value IPC_SET or IPC_RMID, but the
159              effective user ID of the calling process is not the creator  (as
160              found  in msg_perm.cuid) or the owner (as found in msg_perm.uid)
161              of the message queue, and the caller is not  privileged  (Linux:
162              does not have the CAP_SYS_ADMIN capability).
163
164       EPERM  An  attempt (IPC_SET) was made to increase msg_qbytes beyond the
165              system parameter  MSGMNB,  but  the  caller  is  not  privileged
166              (Linux: does not have the CAP_SYS_RESOURCE capability).
167

CONFORMING TO

169       POSIX.1-2001, POSIX.1-2008, SVr4.
170

NOTES

172       The  inclusion of <sys/types.h> and <sys/ipc.h> isn't required on Linux
173       or by any version of POSIX.  However, some old implementations required
174       the inclusion of these header files, and the SVID also documented their
175       inclusion.  Applications intended to be portable to  such  old  systems
176       may need to include these header files.
177
178       The  IPC_INFO, MSG_STAT and MSG_INFO operations are used by the ipcs(1)
179       program to provide information on allocated resources.  In  the  future
180       these may modified or moved to a /proc filesystem interface.
181
182       Various  fields  in the struct msqid_ds were typed as short under Linux
183       2.2 and have become long under Linux 2.4.  To take advantage of this, a
184       recompilation  under glibc-2.1.91 or later should suffice.  (The kernel
185       distinguishes old and new calls by an IPC_64 flag in cmd.)
186

SEE ALSO

188       msgget(2),  msgrcv(2),  msgsnd(2),   capabilities(7),   mq_overview(7),
189       sysvipc(7)
190

COLOPHON

192       This  page  is  part of release 5.02 of the Linux man-pages project.  A
193       description of the project, information about reporting bugs,  and  the
194       latest     version     of     this    page,    can    be    found    at
195       https://www.kernel.org/doc/man-pages/.
196
197
198
199Linux                             2019-08-02                         MSGCTL(2)
Impressum