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 2020-04-11 "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; /* Creation time/time of last
67 modification via msgctl() */
68 unsigned long __msg_cbytes; /* Current number of bytes in
69 queue (nonstandard) */
70 msgqnum_t msg_qnum; /* Current number of messages
72 msglen_t msg_qbytes; /* Maximum number of bytes
74 pid_t msg_lspid; /* PID of last msgsnd(2) */
75 pid_t msg_lrpid; /* PID of last msgrcv(2) */
82 structure are as follows:
87 structure (see below) that specifies the access permissions on the message
91 Number of messages currently on the message queue.
94 Maximum number of bytes of message text allowed on the message
98 ID of the process that performed the last
103 ID of the process that performed the last
118 Time of creation of queue or time of last
125 structure is defined as follows
126 (the highlighted fields are settable using
132 key_t __key; /* Key supplied to msgget(2) */
133 uid_t \fBuid\fP; /* Effective UID of owner */
134 gid_t \fBgid\fP; /* Effective GID of owner */
135 uid_t cuid; /* Effective UID of creator */
136 gid_t cgid; /* Effective GID of creator */
137 unsigned short \fBmode\fP; /* Permissions */
138 unsigned short __seq; /* Sequence number */
143 The least significant 9 bits of the
147 structure define the access permissions for the message queue.
148 The permission bits are as follows:
159 Bits 0100, 0010, and 0001 (the execute bits) are unused by the system.
166 Copy information from the kernel data structure associated with
170 structure pointed to by
172 The caller must have read permission on the message queue.
175 Write the values of some members of the
177 structure pointed to by
179 to the kernel data structure associated with this message queue,
183 The following members of the structure are updated:
187 and (the least significant 9 bits of)
189 The effective UID of the calling process must match the owner
192 .RI ( msg_perm.cuid )
193 of the message queue, or the caller must be privileged.
194 Appropriate privilege (Linux: the
196 capability) is required to raise the
198 value beyond the system parameter
202 Immediately remove the message queue,
203 awakening all waiting reader and writer processes (with an error
208 The calling process must have appropriate privileges
209 or its effective user ID must be either that of the creator or owner
210 of the message queue.
211 The third argument to
213 is ignored in this case.
215 .BR IPC_INFO " (Linux-specific)"
216 Return information about system-wide message queue limits and
217 parameters in the structure pointed to by
219 This structure is of type
221 (thus, a cast is required),
226 feature test macro is defined:
231 int msgpool; /* Size in kibibytes of buffer pool
232 used to hold message data;
233 unused within kernel */
234 int msgmap; /* Maximum number of entries in message
235 map; unused within kernel */
236 int msgmax; /* Maximum number of bytes that can be
237 written in a single message */
238 int msgmnb; /* Maximum number of bytes that can be
239 written to queue; used to initialize
240 msg_qbytes during queue creation
242 int msgmni; /* Maximum number of message queues */
243 int msgssz; /* Message segment size;
244 unused within kernel */
245 int msgtql; /* Maximum number of messages on all queues
246 in system; unused within kernel */
247 unsigned short int msgseg;
248 /* Maximum number of segments;
249 unused within kernel */
259 settings can be changed via
261 files of the same name; see
265 .BR MSG_INFO " (Linux-specific)"
268 structure containing the same information as for
270 except that the following fields are returned with information
271 about system resources consumed by message queues: the
273 field returns the number of message queues that currently exist
276 field returns the total number of messages in all queues
277 on the system; and the
279 field returns the total number of bytes in all messages
280 in all queues on the system.
282 .BR MSG_STAT " (Linux-specific)"
289 argument is not a queue identifier, but instead an index into
290 the kernel's internal array that maintains information about
291 all message queues on the system.
293 .BR MSG_STAT_ANY " (Linux-specific, since Linux 4.17)"
300 is not checked for read access for
302 meaning that any user can employ this operation (just as any user may read
303 .IR /proc/sysvipc/msg
304 to obtain the same information).
316 operation returns the index of the highest used entry in the
317 kernel's internal array recording information about all
319 (This information can be used with repeated
323 operations to obtain information about all queues on the system.)
328 operation returns the identifier of the queue whose index was given in
331 On error, \-1 is returned with
333 indicating the error.
337 is set to one of the following:
346 but the calling process does not have read permission on the message queue
348 and does not have the
350 capability in the user namespace that governs its IPC namespace.
359 but the address pointed to by
364 The message queue was removed.
373 operation, the index value specified in
375 referred to an array slot that is currently unused.
384 but the effective user ID of the calling process is not the creator
390 of the message queue,
391 and the caller is not privileged (Linux: does not have the
400 beyond the system parameter
402 but the caller is not privileged (Linux: does not have the
406 POSIX.1-2001, POSIX.1-2008, SVr4.
407 .\" SVID does not document the EIDRM error condition.
413 isn't required on Linux or by any version of POSIX.
415 some old implementations required the inclusion of these header files,
416 and the SVID also documented their inclusion.
417 Applications intended to be portable to such old systems may need
418 to include these header files.
419 .\" Like Linux, the FreeBSD man pages still document
420 .\" the inclusion of these header files.
427 operations are used by the
429 program to provide information on allocated resources.
430 In the future these may modified or moved to a
432 filesystem interface.
434 Various fields in the \fIstruct msqid_ds\fP were
441 To take advantage of this,
442 a recompilation under glibc-2.1.91 or later should suffice.
443 (The kernel distinguishes old and new calls by an
451 .BR capabilities (7),