1MSGCTL(2) Linux Programmer's Manual MSGCTL(2)
2
3
4
6 msgctl - message control operations
7
9 #include <sys/types.h>
10 #include <sys/ipc.h>
11 #include <sys/msg.h>
12
13 int msgctl(int msqid, int cmd, struct msqid_ds *buf);
14
16 msgctl() performs the control operation specified by cmd on the message
17 queue with identifier msqid.
18
19 The msqid_ds data structure is defined in <sys/msg.h> as follows:
20
21 struct msqid_ds {
22 struct ipc_perm msg_perm; /* Ownership and permissions */
23 time_t msg_stime; /* Time of last msgsnd(2) */
24 time_t msg_rtime; /* Time of last msgrcv(2) */
25 time_t msg_ctime; /* Time of last change */
26 unsigned long __msg_cbytes; /* Current number of bytes in
27 queue (nonstandard) */
28 msgqnum_t msg_qnum; /* Current number of messages
29 in queue */
30 msglen_t msg_qbytes; /* Maximum number of bytes
31 allowed in queue */
32 pid_t msg_lspid; /* PID of last msgsnd(2) */
33 pid_t msg_lrpid; /* PID of last msgrcv(2) */
34 };
35
36 The ipc_perm structure is defined in <sys/ipc.h> as follows (the high‐
37 lighted fields are settable using IPC_SET):
38
39 struct ipc_perm {
40 key_t __key; /* Key supplied to msgget(2) */
41 uid_t uid; /* Effective UID of owner */
42 gid_t gid; /* Effective GID of owner */
43 uid_t cuid; /* Effective UID of creator */
44 gid_t cgid; /* Effective GID of creator */
45 unsigned short mode; /* Permissions */
46 unsigned short __seq; /* Sequence number */
47 };
48
49 Valid values for cmd are:
50
51 IPC_STAT
52 Copy information from the kernel data structure associated with
53 msqid into the msqid_ds structure pointed to by buf. The caller
54 must have read permission on the message queue.
55
56 IPC_SET
57 Write the values of some members of the msqid_ds structure
58 pointed to by buf to the kernel data structure associated with
59 this message queue, updating also its msg_ctime member. The
60 following members of the structure are updated: msg_qbytes,
61 msg_perm.uid, msg_perm.gid, and (the least significant 9 bits
62 of) msg_perm.mode. The effective UID of the calling process
63 must match the owner (msg_perm.uid) or creator (msg_perm.cuid)
64 of the message queue, or the caller must be privileged. Appro‐
65 priate privilege (Linux: the CAP_IPC_RESOURCE capability) is
66 required to raise the msg_qbytes value beyond the system parame‐
67 ter MSGMNB.
68
69 IPC_RMID
70 Immediately remove the message queue, awakening all waiting
71 reader and writer processes (with an error return and errno set
72 to EIDRM). The calling process must have appropriate privileges
73 or its effective user ID must be either that of the creator or
74 owner of the message queue.
75
76 IPC_INFO (Linux-specific)
77 Returns information about system-wide message queue limits and
78 parameters in the structure pointed to by buf. This structure
79 is of type msginfo (thus, a cast is required), defined in
80 <sys/msg.h> if the _GNU_SOURCE feature test macro is defined:
81
82 struct msginfo {
83 int msgpool; /* Size in kibibytes of buffer pool
84 used to hold message data;
85 unused within kernel */
86 int msgmap; /* Maximum number of entries in message
87 map; unused within kernel */
88 int msgmax; /* Maximum number of bytes that can be
89 written in a single message */
90 int msgmnb; /* Maximum number of bytes that can be
91 written to queue; used to initialize
92 msg_qbytes during queue creation
93 (msgget(2)) */
94 int msgmni; /* Maximum number of message queues */
95 int msgssz; /* Message segment size;
96 unused within kernel */
97 int msgtql; /* Maximum number of messages on all queues
98 in system; unused within kernel */
99 unsigned short int msgseg;
100 /* Maximum number of segments;
101 unused within kernel */
102 };
103
104 The msgmni, msgmax, and msgmnb settings can be changed via /proc
105 files of the same name; see proc(5) for details.
106
107 MSG_INFO (Linux-specific)
108 Returns a msginfo structure containing the same information as
109 for IPC_INFO, except that the following fields are returned with
110 information about system resources consumed by message queues:
111 the msgpool field returns the number of message queues that cur‐
112 rently exist on the system; the msgmap field returns the total
113 number of messages in all queues on the system; and the msgtql
114 field returns the total number of bytes in all messages in all
115 queues on the system.
116
117 MSG_STAT (Linux-specific)
118 Returns a msqid_ds structure as for IPC_STAT. However, the
119 msqid argument is not a queue identifier, but instead an index
120 into the kernel's internal array that maintains information
121 about all message queues on the system.
122
124 On success, IPC_STAT, IPC_SET, and IPC_RMID return 0. A successful
125 IPC_INFO or MSG_INFO operation returns the index of the highest used
126 entry in the kernel's internal array recording information about all
127 message queues. (This information can be used with repeated MSG_STAT
128 operations to obtain information about all queues on the system.) A
129 successful MSG_STAT operation returns the identifier of the queue whose
130 index was given in msqid.
131
132 On error, -1 is returned with errno indicating the error.
133
135 On failure, errno is set to one of the following:
136
137 EACCES The argument cmd is equal to IPC_STAT or MSG_STAT, but the call‐
138 ing process does not have read permission on the message queue
139 msqid, and does not have the CAP_IPC_OWNER capability.
140
141 EFAULT The argument cmd has the value IPC_SET or IPC_STAT, but the
142 address pointed to by buf isn't accessible.
143
144 EIDRM The message queue was removed.
145
146 EINVAL Invalid value for cmd or msqid. Or: for a MSG_STAT operation,
147 the index value specified in msqid referred to an array slot
148 that is currently unused.
149
150 EPERM The argument cmd has the value IPC_SET or IPC_RMID, but the
151 effective user ID of the calling process is not the creator (as
152 found in msg_perm.cuid) or the owner (as found in msg_perm.uid)
153 of the message queue, and the process is not privileged (Linux:
154 it does not have the CAP_SYS_ADMIN capability).
155
157 SVr4, POSIX.1-2001.
158
160 The IPC_INFO, MSG_STAT and MSG_INFO operations are used by the ipcs(1)
161 program to provide information on allocated resources. In the future
162 these may modified or moved to a /proc file system interface.
163
164 Various fields in the struct msqid_ds were typed as short under Linux
165 2.2 and have become long under Linux 2.4. To take advantage of this, a
166 recompilation under glibc-2.1.91 or later should suffice. (The kernel
167 distinguishes old and new calls by an IPC_64 flag in cmd.)
168
170 msgget(2), msgrcv(2), msgsnd(2), capabilities(7), mq_overview(7),
171 svipc(7)
172
174 This page is part of release 3.25 of the Linux man-pages project. A
175 description of the project, and information about reporting bugs, can
176 be found at http://www.kernel.org/doc/man-pages/.
177
178
179
180Linux 2008-08-06 MSGCTL(2)