1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
27 .\" Modified Sun Feb 18 01:59:29 2001 by Andries E. Brouwer <aeb@cwi.nl>
28 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added notes on CAP_IPC_OWNER requirement
30 .\" Modified, 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
32 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Language and formatting clean-ups
34 .\" Added msqid_ds and ipc_perm structure definitions
35 .\" 2005-08-02, mtk: Added IPC_INFO, MSG_INFO, MSG_STAT descriptions
36 .\" 2018-03-20, dbueso: Added MSG_STAT_ANY description.
38 .TH MSGCTL 2 2019-03-06 "Linux" "Linux Programmer's Manual"
40 msgctl \- System V message control operations
43 .B #include <sys/types.h>
44 .B #include <sys/ipc.h>
45 .B #include <sys/msg.h>
47 .BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
51 performs the control operation specified by
53 on the System\ V message queue with identifier
58 data structure is defined in \fI<sys/msg.h>\fP as follows:
63 struct ipc_perm msg_perm; /* Ownership and permissions */
64 time_t msg_stime; /* Time of last msgsnd(2) */
65 time_t msg_rtime; /* Time of last msgrcv(2) */
66 time_t msg_ctime; /* Time of last change */
67 unsigned long __msg_cbytes; /* Current number of bytes in
68 queue (nonstandard) */
69 msgqnum_t msg_qnum; /* Current number of messages
71 msglen_t msg_qbytes; /* Maximum number of bytes
73 pid_t msg_lspid; /* PID of last msgsnd(2) */
74 pid_t msg_lrpid; /* PID of last msgrcv(2) */
81 structure is defined as follows
82 (the highlighted fields are settable using
88 key_t __key; /* Key supplied to msgget(2) */
89 uid_t \fBuid\fP; /* Effective UID of owner */
90 gid_t \fBgid\fP; /* Effective GID of owner */
91 uid_t cuid; /* Effective UID of creator */
92 gid_t cgid; /* Effective GID of creator */
93 unsigned short \fBmode\fP; /* Permissions */
94 unsigned short __seq; /* Sequence number */
104 Copy information from the kernel data structure associated with
108 structure pointed to by
110 The caller must have read permission on the message queue.
113 Write the values of some members of the
115 structure pointed to by
117 to the kernel data structure associated with this message queue,
121 The following members of the structure are updated:
125 and (the least significant 9 bits of)
127 The effective UID of the calling process must match the owner
130 .RI ( msg_perm.cuid )
131 of the message queue, or the caller must be privileged.
132 Appropriate privilege (Linux: the
134 capability) is required to raise the
136 value beyond the system parameter
140 Immediately remove the message queue,
141 awakening all waiting reader and writer processes (with an error
146 The calling process must have appropriate privileges
147 or its effective user ID must be either that of the creator or owner
148 of the message queue.
149 The third argument to
151 is ignored in this case.
153 .BR IPC_INFO " (Linux-specific)"
154 Return information about system-wide message queue limits and
155 parameters in the structure pointed to by
157 This structure is of type
159 (thus, a cast is required),
164 feature test macro is defined:
169 int msgpool; /* Size in kibibytes of buffer pool
170 used to hold message data;
171 unused within kernel */
172 int msgmap; /* Maximum number of entries in message
173 map; unused within kernel */
174 int msgmax; /* Maximum number of bytes that can be
175 written in a single message */
176 int msgmnb; /* Maximum number of bytes that can be
177 written to queue; used to initialize
178 msg_qbytes during queue creation
180 int msgmni; /* Maximum number of message queues */
181 int msgssz; /* Message segment size;
182 unused within kernel */
183 int msgtql; /* Maximum number of messages on all queues
184 in system; unused within kernel */
185 unsigned short int msgseg;
186 /* Maximum number of segments;
187 unused within kernel */
197 settings can be changed via
199 files of the same name; see
203 .BR MSG_INFO " (Linux-specific)"
206 structure containing the same information as for
208 except that the following fields are returned with information
209 about system resources consumed by message queues: the
211 field returns the number of message queues that currently exist
214 field returns the total number of messages in all queues
215 on the system; and the
217 field returns the total number of bytes in all messages
218 in all queues on the system.
220 .BR MSG_STAT " (Linux-specific)"
227 argument is not a queue identifier, but instead an index into
228 the kernel's internal array that maintains information about
229 all message queues on the system.
231 .BR MSG_STAT_ANY " (Linux-specific, since Linux 4.17)"
238 is not checked for read access for
240 meaning that any user can employ this operation (just as any user may read
241 .IR /proc/sysvipc/msg
242 to obtain the same information).
254 operation returns the index of the highest used entry in the
255 kernel's internal array recording information about all
257 (This information can be used with repeated
261 operations to obtain information about all queues on the system.)
266 operation returns the identifier of the queue whose index was given in
269 On error, \-1 is returned with
271 indicating the error.
275 is set to one of the following:
284 but the calling process does not have read permission on the message queue
286 and does not have the
288 capability in the user namespace that governs its IPC namespace.
297 but the address pointed to by
302 The message queue was removed.
311 operation, the index value specified in
313 referred to an array slot that is currently unused.
322 but the effective user ID of the calling process is not the creator
328 of the message queue,
329 and the caller is not privileged (Linux: does not have the
338 beyond the system parameter
340 but the caller is not privileged (Linux: does not have the
344 POSIX.1-2001, POSIX.1-2008, SVr4.
345 .\" SVID does not document the EIDRM error condition.
351 isn't required on Linux or by any version of POSIX.
353 some old implementations required the inclusion of these header files,
354 and the SVID also documented their inclusion.
355 Applications intended to be portable to such old systems may need
356 to include these header files.
357 .\" Like Linux, the FreeBSD man pages still document
358 .\" the inclusion of these header files.
365 operations are used by the
367 program to provide information on allocated resources.
368 In the future these may modified or moved to a
370 filesystem interface.
372 Various fields in the \fIstruct msqid_ds\fP were
379 To take advantage of this,
380 a recompilation under glibc-2.1.91 or later should suffice.
381 (The kernel distinguishes old and new calls by an
389 .BR capabilities (7),