537 lines
16 KiB
HTML
537 lines
16 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of MSGCTL</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>MSGCTL</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-08-02<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
msgctl - System V message control operations
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/sys/ipc.h">sys/ipc.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/sys/msg.h">sys/msg.h</A>></B>
|
|
|
|
<B>int msgctl(int </B><I>msqid</I><B>, int </B><I>cmd</I><B>, struct msqid_ds *</B><I>buf</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>msgctl</B>()
|
|
|
|
performs the control operation specified by
|
|
<I>cmd</I>
|
|
|
|
on the System V message queue with identifier
|
|
<I>msqid</I>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>msqid_ds</I>
|
|
|
|
data structure is defined in <I><<A HREF="file:///usr/include/sys/msg.h">sys/msg.h</A>></I> as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct msqid_ds {
|
|
<BR> struct ipc_perm msg_perm; /* Ownership and permissions */
|
|
<BR> time_t msg_stime; /* Time of last <A HREF="/cgi-bin/man/man2html?2+msgsnd">msgsnd</A>(2) */
|
|
<BR> time_t msg_rtime; /* Time of last <A HREF="/cgi-bin/man/man2html?2+msgrcv">msgrcv</A>(2) */
|
|
<BR> time_t msg_ctime; /* Time of last change */
|
|
<BR> unsigned long __msg_cbytes; /* Current number of bytes in
|
|
<BR> queue (nonstandard) */
|
|
<BR> msgqnum_t msg_qnum; /* Current number of messages
|
|
<BR> in queue */
|
|
<BR> msglen_t msg_qbytes; /* Maximum number of bytes
|
|
<BR> allowed in queue */
|
|
<BR> pid_t msg_lspid; /* PID of last <A HREF="/cgi-bin/man/man2html?2+msgsnd">msgsnd</A>(2) */
|
|
<BR> pid_t msg_lrpid; /* PID of last <A HREF="/cgi-bin/man/man2html?2+msgrcv">msgrcv</A>(2) */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>ipc_perm</I>
|
|
|
|
structure is defined as follows
|
|
(the highlighted fields are settable using
|
|
<B>IPC_SET</B>):
|
|
|
|
<P>
|
|
|
|
|
|
|
|
struct ipc_perm {
|
|
<BR> key_t __key; /* Key supplied to <A HREF="/cgi-bin/man/man2html?2+msgget">msgget</A>(2) */
|
|
<BR> uid_t <B>uid</B>; /* Effective UID of owner */
|
|
<BR> gid_t <B>gid</B>; /* Effective GID of owner */
|
|
<BR> uid_t cuid; /* Effective UID of creator */
|
|
<BR> gid_t cgid; /* Effective GID of creator */
|
|
<BR> unsigned short <B>mode</B>; /* Permissions */
|
|
<BR> unsigned short __seq; /* Sequence number */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
Valid values for
|
|
<I>cmd</I>
|
|
|
|
are:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>IPC_STAT</B>
|
|
|
|
<DD>
|
|
Copy information from the kernel data structure associated with
|
|
<I>msqid</I>
|
|
|
|
into the
|
|
<I>msqid_ds</I>
|
|
|
|
structure pointed to by
|
|
<I>buf</I>.
|
|
|
|
The caller must have read permission on the message queue.
|
|
<DT id="2"><B>IPC_SET</B>
|
|
|
|
<DD>
|
|
Write the values of some members of the
|
|
<I>msqid_ds</I>
|
|
|
|
structure pointed to by
|
|
<I>buf</I>
|
|
|
|
to the kernel data structure associated with this message queue,
|
|
updating also its
|
|
<I>msg_ctime</I>
|
|
|
|
member.
|
|
The following members of the structure are updated:
|
|
<I>msg_qbytes</I>,
|
|
|
|
<I>msg_perm.uid</I>,
|
|
|
|
<I>msg_perm.gid</I>,
|
|
|
|
and (the least significant 9 bits of)
|
|
<I>msg_perm.mode</I>.
|
|
|
|
The effective UID of the calling process must match the owner
|
|
(<I>msg_perm.uid</I>)
|
|
|
|
or creator
|
|
(<I>msg_perm.cuid</I>)
|
|
|
|
of the message queue, or the caller must be privileged.
|
|
Appropriate privilege (Linux: the
|
|
<B>CAP_SYS_RESOURCE</B>
|
|
|
|
capability) is required to raise the
|
|
<I>msg_qbytes</I>
|
|
|
|
value beyond the system parameter
|
|
<B>MSGMNB</B>.
|
|
|
|
<DT id="3"><B>IPC_RMID</B>
|
|
|
|
<DD>
|
|
Immediately remove the message queue,
|
|
awakening all waiting reader and writer processes (with an error
|
|
return and
|
|
<I>errno</I>
|
|
|
|
set to
|
|
<B>EIDRM</B>).
|
|
|
|
The calling process must have appropriate privileges
|
|
or its effective user ID must be either that of the creator or owner
|
|
of the message queue.
|
|
The third argument to
|
|
<B>msgctl</B>()
|
|
|
|
is ignored in this case.
|
|
<DT id="4"><B>IPC_INFO</B> (Linux-specific)
|
|
|
|
<DD>
|
|
Return information about system-wide message queue limits and
|
|
parameters in the structure pointed to by
|
|
<I>buf</I>.
|
|
|
|
This structure is of type
|
|
<I>msginfo</I>
|
|
|
|
(thus, a cast is required),
|
|
defined in
|
|
<I><<A HREF="file:///usr/include/sys/msg.h">sys/msg.h</A>></I>
|
|
|
|
if the
|
|
<B>_GNU_SOURCE</B>
|
|
|
|
feature test macro is defined:
|
|
<DT id="5"><DD>
|
|
|
|
|
|
struct msginfo {
|
|
<BR> int msgpool; /* Size in kibibytes of buffer pool
|
|
<BR> used to hold message data;
|
|
<BR> unused within kernel */
|
|
<BR> int msgmap; /* Maximum number of entries in message
|
|
<BR> map; unused within kernel */
|
|
<BR> int msgmax; /* Maximum number of bytes that can be
|
|
<BR> written in a single message */
|
|
<BR> int msgmnb; /* Maximum number of bytes that can be
|
|
<BR> written to queue; used to initialize
|
|
<BR> msg_qbytes during queue creation
|
|
<BR> (<A HREF="/cgi-bin/man/man2html?2+msgget">msgget</A>(2)) */
|
|
<BR> int msgmni; /* Maximum number of message queues */
|
|
<BR> int msgssz; /* Message segment size;
|
|
<BR> unused within kernel */
|
|
<BR> int msgtql; /* Maximum number of messages on all queues
|
|
<BR> in system; unused within kernel */
|
|
<BR> unsigned short int msgseg;
|
|
<BR> /* Maximum number of segments;
|
|
<BR> unused within kernel */
|
|
};
|
|
|
|
|
|
<DT id="6"><DD>
|
|
The
|
|
<I>msgmni</I>,
|
|
|
|
<I>msgmax</I>,
|
|
|
|
and
|
|
<I>msgmnb</I>
|
|
|
|
settings can be changed via
|
|
<I>/proc</I>
|
|
|
|
files of the same name; see
|
|
<B><A HREF="/cgi-bin/man/man2html?5+proc">proc</A></B>(5)
|
|
|
|
for details.
|
|
<DT id="7"><B>MSG_INFO</B> (Linux-specific)
|
|
|
|
<DD>
|
|
Return a
|
|
<I>msginfo</I>
|
|
|
|
structure containing the same information as for
|
|
<B>IPC_INFO</B>,
|
|
|
|
except that the following fields are returned with information
|
|
about system resources consumed by message queues: the
|
|
<I>msgpool</I>
|
|
|
|
field returns the number of message queues that currently exist
|
|
on the system; the
|
|
<I>msgmap</I>
|
|
|
|
field returns the total number of messages in all queues
|
|
on the system; and the
|
|
<I>msgtql</I>
|
|
|
|
field returns the total number of bytes in all messages
|
|
in all queues on the system.
|
|
<DT id="8"><B>MSG_STAT</B> (Linux-specific)
|
|
|
|
<DD>
|
|
Return a
|
|
<I>msqid_ds</I>
|
|
|
|
structure as for
|
|
<B>IPC_STAT</B>.
|
|
|
|
However, the
|
|
<I>msqid</I>
|
|
|
|
argument is not a queue identifier, but instead an index into
|
|
the kernel's internal array that maintains information about
|
|
all message queues on the system.
|
|
<DT id="9"><B>MSG_STAT_ANY</B> (Linux-specific, since Linux 4.17)
|
|
|
|
<DD>
|
|
Return a
|
|
<I>msqid_ds</I>
|
|
|
|
structure as for
|
|
<B>MSG_STAT</B>.
|
|
|
|
However,
|
|
<I>msg_perm.mode</I>
|
|
|
|
is not checked for read access for
|
|
<I>msqid</I>
|
|
|
|
meaning that any user can employ this operation (just as any user may read
|
|
<I>/proc/sysvipc/msg</I>
|
|
|
|
to obtain the same information).
|
|
</DL>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>IPC_STAT</B>,
|
|
|
|
<B>IPC_SET</B>,
|
|
|
|
and
|
|
<B>IPC_RMID</B>
|
|
|
|
return 0.
|
|
A successful
|
|
<B>IPC_INFO</B>
|
|
|
|
or
|
|
<B>MSG_INFO</B>
|
|
|
|
operation returns the index of the highest used entry in the
|
|
kernel's internal array recording information about all
|
|
message queues.
|
|
(This information can be used with repeated
|
|
<B>MSG_STAT</B>
|
|
|
|
or
|
|
<B>MSG_STAT_ANY</B>
|
|
|
|
operations to obtain information about all queues on the system.)
|
|
A successful
|
|
<B>MSG_STAT</B>
|
|
|
|
or
|
|
<B>MSG_STAT_ANY</B>
|
|
|
|
operation returns the identifier of the queue whose index was given in
|
|
<I>msqid</I>.
|
|
|
|
<P>
|
|
|
|
On error, -1 is returned with
|
|
<I>errno</I>
|
|
|
|
indicating the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
On failure,
|
|
<I>errno</I>
|
|
|
|
is set to one of the following:
|
|
<DL COMPACT>
|
|
<DT id="10"><B>EACCES</B>
|
|
|
|
<DD>
|
|
The argument
|
|
<I>cmd</I>
|
|
|
|
is equal to
|
|
<B>IPC_STAT</B>
|
|
|
|
or
|
|
<B>MSG_STAT</B>,
|
|
|
|
but the calling process does not have read permission on the message queue
|
|
<I>msqid</I>,
|
|
|
|
and does not have the
|
|
<B>CAP_IPC_OWNER</B>
|
|
|
|
capability in the user namespace that governs its IPC namespace.
|
|
<DT id="11"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
The argument
|
|
<I>cmd</I>
|
|
|
|
has the value
|
|
<B>IPC_SET</B>
|
|
|
|
or
|
|
<B>IPC_STAT</B>,
|
|
|
|
but the address pointed to by
|
|
<I>buf</I>
|
|
|
|
isn't accessible.
|
|
<DT id="12"><B>EIDRM</B>
|
|
|
|
<DD>
|
|
The message queue was removed.
|
|
<DT id="13"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
Invalid value for
|
|
<I>cmd</I>
|
|
|
|
or
|
|
<I>msqid</I>.
|
|
|
|
Or: for a
|
|
<B>MSG_STAT</B>
|
|
|
|
operation, the index value specified in
|
|
<I>msqid</I>
|
|
|
|
referred to an array slot that is currently unused.
|
|
<DT id="14"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The argument
|
|
<I>cmd</I>
|
|
|
|
has the value
|
|
<B>IPC_SET</B>
|
|
|
|
or
|
|
<B>IPC_RMID</B>,
|
|
|
|
but the effective user ID of the calling process is not the creator
|
|
(as found in
|
|
<I>msg_perm.cuid</I>)
|
|
|
|
or the owner
|
|
(as found in
|
|
<I>msg_perm.uid</I>)
|
|
|
|
of the message queue,
|
|
and the caller is not privileged (Linux: does not have the
|
|
<B>CAP_SYS_ADMIN</B>
|
|
|
|
capability).
|
|
<DT id="15"><B>EPERM</B>
|
|
|
|
<DD>
|
|
An attempt
|
|
(<B>IPC_SET</B>)
|
|
|
|
was made to increase
|
|
<I>msg_qbytes</I>
|
|
|
|
beyond the system parameter
|
|
<B>MSGMNB</B>,
|
|
|
|
but the caller is not privileged (Linux: does not have the
|
|
<B>CAP_SYS_RESOURCE</B>
|
|
|
|
capability).
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4.
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The inclusion of
|
|
<I><<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></I>
|
|
|
|
and
|
|
<I><<A HREF="file:///usr/include/sys/ipc.h">sys/ipc.h</A>></I>
|
|
|
|
isn't required on Linux or by any version of POSIX.
|
|
However,
|
|
some old implementations required the inclusion of these header files,
|
|
and the SVID also documented their inclusion.
|
|
Applications intended to be portable to such old systems may need
|
|
to include these header files.
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>IPC_INFO</B>,
|
|
|
|
<B>MSG_STAT</B>
|
|
|
|
and
|
|
<B>MSG_INFO</B>
|
|
|
|
operations are used by the
|
|
<B><A HREF="/cgi-bin/man/man2html?1+ipcs">ipcs</A></B>(1)
|
|
|
|
program to provide information on allocated resources.
|
|
In the future these may modified or moved to a
|
|
<I>/proc</I>
|
|
|
|
filesystem interface.
|
|
<P>
|
|
|
|
Various fields in the <I>struct msqid_ds</I> were
|
|
typed as
|
|
<I>short</I>
|
|
|
|
under Linux 2.2
|
|
and have become
|
|
<I>long</I>
|
|
|
|
under Linux 2.4.
|
|
To take advantage of this,
|
|
a recompilation under glibc-2.1.91 or later should suffice.
|
|
(The kernel distinguishes old and new calls by an
|
|
<B>IPC_64</B>
|
|
|
|
flag in
|
|
<I>cmd</I>.)
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgget">msgget</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgrcv">msgrcv</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgsnd">msgsnd</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+sysvipc">sysvipc</A></B>(7)
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="16"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="17"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="18"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="19"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="20"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="21"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="22"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DT id="23"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="24"><A HREF="#lbAJ">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|