1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
25 .\" Modified Sun Feb 18 01:59:29 2001 by Andries E. Brouwer <aeb@cwi.nl>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added notes on CAP_IPC_OWNER requirement
28 .\" Modified, 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
30 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Language and formatting clean-ups
32 .\" Added msqid_ds and ipc_perm structure definitions
33 .\" 2005-08-02, mtk: Added IPC_INFO, MSG_INFO, MSG_STAT descriptions
35 .TH MSGCTL 2 2008-08-06 "Linux" "Linux Programmer's Manual"
37 msgctl \- message control operations
40 .B #include <sys/types.h>
41 .B #include <sys/ipc.h>
42 .B #include <sys/msg.h>
44 .BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
48 performs the control operation specified by
50 on the message queue with identifier
55 data structure is defined in \fI<sys/msg.h>\fP as follows:
60 struct ipc_perm msg_perm; /* Ownership and permissions */
61 time_t msg_stime; /* Time of last msgsnd(2) */
62 time_t msg_rtime; /* Time of last msgrcv(2) */
63 time_t msg_ctime; /* Time of last change */
64 unsigned long __msg_cbytes; /* Current number of bytes in
65 queue (nonstandard) */
66 msgqnum_t msg_qnum; /* Current number of messages
68 msglen_t msg_qbytes; /* Maximum number of bytes
70 pid_t msg_lspid; /* PID of last msgsnd(2) */
71 pid_t msg_lrpid; /* PID of last msgrcv(2) */
78 structure is defined as follows
79 (the highlighted fields are settable using
85 key_t __key; /* Key supplied to msgget(2) */
86 uid_t \fBuid\fP; /* Effective UID of owner */
87 gid_t \fBgid\fP; /* Effective GID of owner */
88 uid_t cuid; /* Effective UID of creator */
89 gid_t cgid; /* Effective GID of creator */
90 unsigned short \fBmode\fP; /* Permissions */
91 unsigned short __seq; /* Sequence number */
101 Copy information from the kernel data structure associated with
105 structure pointed to by
107 The caller must have read permission on the message queue.
110 Write the values of some members of the
112 structure pointed to by
114 to the kernel data structure associated with this message queue,
118 The following members of the structure are updated:
122 and (the least significant 9 bits of)
124 The effective UID of the calling process must match the owner
127 .RI ( msg_perm.cuid )
128 of the message queue, or the caller must be privileged.
129 Appropriate privilege (Linux: the
131 capability) is required to raise the
133 value beyond the system parameter
137 Immediately remove the message queue,
138 awakening all waiting reader and writer processes (with an error
143 The calling process must have appropriate privileges
144 or its effective user ID must be either that of the creator or owner
145 of the message queue.
147 .BR IPC_INFO " (Linux-specific)"
148 Returns information about system-wide message queue limits and
149 parameters in the structure pointed to by
151 This structure is of type
153 (thus, a cast is required),
158 feature test macro is defined:
163 int msgpool; /* Size in kibibytes of buffer pool
164 used to hold message data;
165 unused within kernel */
166 int msgmap; /* Maximum number of entries in message
167 map; unused within kernel */
168 int msgmax; /* Maximum number of bytes that can be
169 written in a single message */
170 int msgmnb; /* Maximum number of bytes that can be
171 written to queue; used to initialize
172 msg_qbytes during queue creation
174 int msgmni; /* Maximum number of message queues */
175 int msgssz; /* Message segment size;
176 unused within kernel */
177 int msgtql; /* Maximum number of messages on all queues
178 in system; unused within kernel */
179 unsigned short int msgseg;
180 /* Maximum number of segments;
181 unused within kernel */
191 settings can be changed via
193 files of the same name; see
197 .BR MSG_INFO " (Linux-specific)"
200 structure containing the same information as for
202 except that the following fields are returned with information
203 about system resources consumed by message queues: the
205 field returns the number of message queues that currently exist
208 field returns the total number of messages in all queues
209 on the system; and the
211 field returns the total number of bytes in all messages
212 in all queues on the system.
214 .BR MSG_STAT " (Linux-specific)"
221 argument is not a queue identifier, but instead an index into
222 the kernel's internal array that maintains information about
223 all message queues on the system.
235 operation returns the index of the highest used entry in the
236 kernel's internal array recording information about all
238 (This information can be used with repeated
240 operations to obtain information about all queues on the system.)
243 operation returns the identifier of the queue whose index was given in
246 On error, \-1 is returned with
248 indicating the error.
252 is set to one of the following:
261 but the calling process does not have read permission on the message queue
263 and does not have the
274 but the address pointed to by
279 The message queue was removed.
288 operation, the index value specified in
290 referred to an array slot that is currently unused.
299 but the effective user ID of the calling process is not the creator
305 of the message queue,
306 and the process is not privileged (Linux: it does not have the
311 .\" SVID does not document the EIDRM error condition.
318 operations are used by the
320 program to provide information on allocated resources.
321 In the future these may modified or moved to a /proc file system
324 Various fields in the \fIstruct msqid_ds\fP were
331 To take advantage of this,
332 a recompilation under glibc-2.1.91 or later should suffice.
333 (The kernel distinguishes old and new calls by an
341 .BR capabilities (7),