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 2021-03-22 "Linux" "Linux Programmer's Manual"
40 msgctl \- System V message control operations
43 .B #include <sys/msg.h>
45 .BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
49 performs the control operation specified by
51 on the System\ V message queue with identifier
56 data structure is defined in \fI<sys/msg.h>\fP as follows:
61 struct ipc_perm msg_perm; /* Ownership and permissions */
62 time_t msg_stime; /* Time of last msgsnd(2) */
63 time_t msg_rtime; /* Time of last msgrcv(2) */
64 time_t msg_ctime; /* Time of creation or last
65 modification by msgctl() */
66 unsigned long msg_cbytes; /* # of bytes in queue */
67 msgqnum_t msg_qnum; /* # number of messages in queue */
68 msglen_t msg_qbytes; /* Maximum # of bytes in queue */
69 pid_t msg_lspid; /* PID of last msgsnd(2) */
70 pid_t msg_lrpid; /* PID of last msgrcv(2) */
77 structure are as follows:
82 structure (see below) that specifies the access permissions on the message
96 Time of creation of queue or time of last
102 Number of bytes in all messages currently on the message queue.
103 This is a nonstandard Linux extension that is not specified in POSIX.
106 Number of messages currently on the message queue.
109 Maximum number of bytes of message text allowed on the message
113 ID of the process that performed the last
118 ID of the process that performed the last
124 structure is defined as follows
125 (the highlighted fields are settable using
131 key_t __key; /* Key supplied to msgget(2) */
132 uid_t \fBuid\fP; /* Effective UID of owner */
133 gid_t \fBgid\fP; /* Effective GID of owner */
134 uid_t cuid; /* Effective UID of creator */
135 gid_t cgid; /* Effective GID of creator */
136 unsigned short \fBmode\fP; /* Permissions */
137 unsigned short __seq; /* Sequence number */
142 The least significant 9 bits of the
146 structure define the access permissions for the message queue.
147 The permission bits are as follows:
158 Bits 0100, 0010, and 0001 (the execute bits) are unused by the system.
165 Copy information from the kernel data structure associated with
169 structure pointed to by
171 The caller must have read permission on the message queue.
174 Write the values of some members of the
176 structure pointed to by
178 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)
190 The effective UID of the calling process must match the owner
193 .RI ( msg_perm.cuid )
194 of the message queue, or the caller must be privileged.
195 Appropriate privilege (Linux: the
197 capability) is required to raise the
199 value beyond the system parameter
203 Immediately remove the message queue,
204 awakening all waiting reader and writer processes (with an error
209 The calling process must have appropriate privileges
210 or its effective user ID must be either that of the creator or owner
211 of the message queue.
212 The third argument to
214 is ignored in this case.
216 .BR IPC_INFO " (Linux-specific)"
217 Return information about system-wide message queue limits and
218 parameters in the structure pointed to by
220 This structure is of type
222 (thus, a cast is required),
227 feature test macro is defined:
232 int msgpool; /* Size in kibibytes of buffer pool
233 used to hold message data;
234 unused within kernel */
235 int msgmap; /* Maximum number of entries in message
236 map; unused within kernel */
237 int msgmax; /* Maximum number of bytes that can be
238 written in a single message */
239 int msgmnb; /* Maximum number of bytes that can be
240 written to queue; used to initialize
241 msg_qbytes during queue creation
243 int msgmni; /* Maximum number of message queues */
244 int msgssz; /* Message segment size;
245 unused within kernel */
246 int msgtql; /* Maximum number of messages on all queues
247 in system; unused within kernel */
248 unsigned short msgseg;
249 /* Maximum number of segments;
250 unused within kernel */
260 settings can be changed via
262 files of the same name; see
266 .BR MSG_INFO " (Linux-specific)"
269 structure containing the same information as for
271 except that the following fields are returned with information
272 about system resources consumed by message queues: the
274 field returns the number of message queues that currently exist
277 field returns the total number of messages in all queues
278 on the system; and the
280 field returns the total number of bytes in all messages
281 in all queues on the system.
283 .BR MSG_STAT " (Linux-specific)"
290 argument is not a queue identifier, but instead an index into
291 the kernel's internal array that maintains information about
292 all message queues on the system.
294 .BR MSG_STAT_ANY " (Linux-specific, since Linux 4.17)"
301 is not checked for read access for
303 meaning that any user can employ this operation (just as any user may read
304 .IR /proc/sysvipc/msg
305 to obtain the same information).
317 operation returns the index of the highest used entry in the
318 kernel's internal array recording information about all
320 (This information can be used with repeated
324 operations to obtain information about all queues on the system.)
329 operation returns the identifier of the queue whose index was given in
332 On failure, \-1 is returned and
334 is set to indicate the error.
344 but the calling process does not have read permission on the message queue
346 and does not have the
348 capability in the user namespace that governs its IPC namespace.
357 but the address pointed to by
362 The message queue was removed.
371 operation, the index value specified in
373 referred to an array slot that is currently unused.
382 but the effective user ID of the calling process is not the creator
388 of the message queue,
389 and the caller is not privileged (Linux: does not have the
398 beyond the system parameter
400 but the caller is not privileged (Linux: does not have the
404 POSIX.1-2001, POSIX.1-2008, SVr4.
405 .\" SVID does not document the EIDRM error condition.
412 operations are used by the
414 program to provide information on allocated resources.
415 In the future these may modified or moved to a
417 filesystem interface.
419 Various fields in the \fIstruct msqid_ds\fP were
426 To take advantage of this,
427 a recompilation under glibc-2.1.91 or later should suffice.
428 (The kernel distinguishes old and new calls by an
436 .BR capabilities (7),