1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
7 .\" Modified Sun Feb 18 01:59:29 2001 by Andries E. Brouwer <aeb@cwi.nl>
8 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
9 .\" Added notes on CAP_IPC_OWNER requirement
10 .\" Modified, 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
11 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
12 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
13 .\" Language and formatting clean-ups
14 .\" Added msqid_ds and ipc_perm structure definitions
15 .\" 2005-08-02, mtk: Added IPC_INFO, MSG_INFO, MSG_STAT descriptions
16 .\" 2018-03-20, dbueso: Added MSG_STAT_ANY description.
18 .TH MSGCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
20 msgctl \- System V message control operations
23 .RI ( libc ", " \-lc )
26 .B #include <sys/msg.h>
28 .BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
32 performs the control operation specified by
34 on the System\ V message queue with identifier
39 data structure is defined in \fI<sys/msg.h>\fP as follows:
44 struct ipc_perm msg_perm; /* Ownership and permissions */
45 time_t msg_stime; /* Time of last msgsnd(2) */
46 time_t msg_rtime; /* Time of last msgrcv(2) */
47 time_t msg_ctime; /* Time of creation or last
48 modification by msgctl() */
49 unsigned long msg_cbytes; /* # of bytes in queue */
50 msgqnum_t msg_qnum; /* # number of messages in queue */
51 msglen_t msg_qbytes; /* Maximum # of bytes in queue */
52 pid_t msg_lspid; /* PID of last msgsnd(2) */
53 pid_t msg_lrpid; /* PID of last msgrcv(2) */
60 structure are as follows:
65 structure (see below) that specifies the access permissions on the message
79 Time of creation of queue or time of last
85 Number of bytes in all messages currently on the message queue.
86 This is a nonstandard Linux extension that is not specified in POSIX.
89 Number of messages currently on the message queue.
92 Maximum number of bytes of message text allowed on the message
96 ID of the process that performed the last
101 ID of the process that performed the last
107 structure is defined as follows
108 (the highlighted fields are settable using
114 key_t __key; /* Key supplied to msgget(2) */
115 uid_t \fBuid\fP; /* Effective UID of owner */
116 gid_t \fBgid\fP; /* Effective GID of owner */
117 uid_t cuid; /* Effective UID of creator */
118 gid_t cgid; /* Effective GID of creator */
119 unsigned short \fBmode\fP; /* Permissions */
120 unsigned short __seq; /* Sequence number */
125 The least significant 9 bits of the
129 structure define the access permissions for the message queue.
130 The permission bits are as follows:
141 Bits 0100, 0010, and 0001 (the execute bits) are unused by the system.
148 Copy information from the kernel data structure associated with
152 structure pointed to by
154 The caller must have read permission on the message queue.
157 Write the values of some members of the
159 structure pointed to by
161 to the kernel data structure associated with this message queue,
166 The following members of the structure are updated:
170 and (the least significant 9 bits of)
173 The effective UID of the calling process must match the owner
176 .RI ( msg_perm.cuid )
177 of the message queue, or the caller must be privileged.
178 Appropriate privilege (Linux: the
180 capability) is required to raise the
182 value beyond the system parameter
186 Immediately remove the message queue,
187 awakening all waiting reader and writer processes (with an error
192 The calling process must have appropriate privileges
193 or its effective user ID must be either that of the creator or owner
194 of the message queue.
195 The third argument to
197 is ignored in this case.
199 .BR IPC_INFO " (Linux-specific)"
200 Return information about system-wide message queue limits and
201 parameters in the structure pointed to by
203 This structure is of type
205 (thus, a cast is required),
210 feature test macro is defined:
215 int msgpool; /* Size in kibibytes of buffer pool
216 used to hold message data;
217 unused within kernel */
218 int msgmap; /* Maximum number of entries in message
219 map; unused within kernel */
220 int msgmax; /* Maximum number of bytes that can be
221 written in a single message */
222 int msgmnb; /* Maximum number of bytes that can be
223 written to queue; used to initialize
224 msg_qbytes during queue creation
226 int msgmni; /* Maximum number of message queues */
227 int msgssz; /* Message segment size;
228 unused within kernel */
229 int msgtql; /* Maximum number of messages on all queues
230 in system; unused within kernel */
231 unsigned short msgseg;
232 /* Maximum number of segments;
233 unused within kernel */
243 settings can be changed via
245 files of the same name; see
249 .BR MSG_INFO " (Linux-specific)"
252 structure containing the same information as for
254 except that the following fields are returned with information
255 about system resources consumed by message queues: the
257 field returns the number of message queues that currently exist
260 field returns the total number of messages in all queues
261 on the system; and the
263 field returns the total number of bytes in all messages
264 in all queues on the system.
266 .BR MSG_STAT " (Linux-specific)"
273 argument is not a queue identifier, but instead an index into
274 the kernel's internal array that maintains information about
275 all message queues on the system.
277 .BR MSG_STAT_ANY " (Linux-specific, since Linux 4.17)"
284 is not checked for read access for
286 meaning that any user can employ this operation (just as any user may read
288 to obtain the same information).
300 operation returns the index of the highest used entry in the
301 kernel's internal array recording information about all
303 (This information can be used with repeated
307 operations to obtain information about all queues on the system.)
312 operation returns the identifier of the queue whose index was given in
315 On failure, \-1 is returned and
317 is set to indicate the error.
327 but the calling process does not have read permission on the message queue
329 and does not have the
331 capability in the user namespace that governs its IPC namespace.
340 but the address pointed to by
345 The message queue was removed.
354 operation, the index value specified in
356 referred to an array slot that is currently unused.
365 but the effective user ID of the calling process is not the creator
371 of the message queue,
372 and the caller is not privileged (Linux: does not have the
381 beyond the system parameter
383 but the caller is not privileged (Linux: does not have the
387 POSIX.1-2001, POSIX.1-2008, SVr4.
388 .\" SVID does not document the EIDRM error condition.
395 operations are used by the
397 program to provide information on allocated resources.
398 In the future these may modified or moved to a
400 filesystem interface.
402 Various fields in the \fIstruct msqid_ds\fP were
409 To take advantage of this,
410 a recompilation under glibc-2.1.91 or later should suffice.
411 (The kernel distinguishes old and new calls by an
419 .BR capabilities (7),