371 lines
9.8 KiB
HTML
371 lines
9.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>msgget()-Get Message Queue</title>
|
|
<!-- Begin Header Records ========================================== -->
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Change History: -->
|
|
<!-- YYMMDD USERID Change description -->
|
|
<!-- Direct1 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<!-- Edited by Kersten Feb 02 -->
|
|
<!-- This file has undergone html cleanup on 05/01/02 by JET -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<!--End Header Records -->
|
|
<!-- Java sync-link -->
|
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
|
</script>
|
|
|
|
<a name="Top_Of_Page"></a>
|
|
|
|
<h2>msgget()--Get Message Queue</h2>
|
|
|
|
<div class="box" style="width: 60%;">
|
|
<br>
|
|
Syntax<br>
|
|
<pre>
|
|
#include <sys/msg.h>
|
|
#include <sys/stat.h>
|
|
|
|
int msgget(key_t <em>key</em>, int <em>msgflg</em>);
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QP0ZUSHR<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>msgget()</strong> function either creates a new message queue
|
|
or returns the message queue identifier associated with the <em>key</em>
|
|
parameter for an existing message queue. A new message queue is created if one
|
|
of the following is true:</p>
|
|
<ul>
|
|
<li>The <em>key</em> parameter is equal to IPC_PRIVATE.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The <em>key</em> parameter does not already have a message queue identifier
|
|
associated with it and the IPC_CREAT flag is specified in the <em>msgflg</em> parameter.<br>
|
|
<br>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
<p>The system maintains status information about a message queue which can be
|
|
retrieved with the <a href="ipcmsgct.htm">msgctl()</a> function. When a new
|
|
message queue is created, the system initializes the members of the
|
|
<samp>msqid_ds</samp> structure as follows: </p>
|
|
|
|
<ul>
|
|
<li><samp>msg_perm.cuid</samp> and <samp>msg_perm.uid</samp> are set equal to
|
|
the effective user ID of the calling thread.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><samp>msg_perm.cgid</samp> and <samp>msg_perm.gid</samp> are set equal to
|
|
the effective group ID of the calling thread.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The low-order 9 bits of <samp>msg_perm.mode</samp> are set equal to the
|
|
low-order 9 bits of the <em>msgflg</em> parameter.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><samp>msg_qbytes</samp> is set equal to the system limit.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><samp>msg_ctime</samp> is set equal to the current time.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><samp>msg_qnum</samp>, <samp>msg_lspid</samp>, <samp>msg_lrpid</samp>,
|
|
<samp>msg_stime</samp>, and <samp>msg_rtime</samp> are set equal to 0.<br>
|
|
<br>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<br>
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong>key</strong></dt>
|
|
|
|
<dd>(Input) Key associated with the message queue. A key of
|
|
IPC_PRIVATE (0x00000000) guarantees that a unique message queue is created. A key also can
|
|
be specified by the caller or generated by the <a href="p0zftok.htm">ftok()</a>
|
|
function.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong>msgflg</strong></dt>
|
|
|
|
<dd>(Input) Operations and permissions flag.
|
|
The value of <em>msgflg</em> is either zero or is obtained by performing an OR
|
|
operation on one or more of the following constants:</dd>
|
|
|
|
|
|
|
|
<dt><strong>S_IRUSR (0x00000100)</strong></dt>
|
|
<dd>Allow the owner of the message queue to read from it.</dd>
|
|
|
|
<dt><strong>S_IWUSR (0x00000080)</strong></dt>
|
|
<dd>Allow the owner of the message queue to write to it.</dd>
|
|
|
|
<dt><strong>S_IRGRP (0x00000020)</strong></dt>
|
|
<dd>Allow the group of the message queue to read from it.</dd>
|
|
|
|
<dt><strong>S_IWGRP (0x00000010)</strong></dt>
|
|
<dd>Allow the group of the message queue to write to it.</dd>
|
|
|
|
<dt><strong>S_IROTH (0x00000004)</strong></dt>
|
|
<dd>Allow others to read from the message queue.</dd>
|
|
|
|
<dt><strong>S_IWOTH (0x00000002)</strong></dt>
|
|
<dd>Allow others to write to the message queue.</dd>
|
|
|
|
<dt><strong>IPC_CREAT (0x00000200)</strong></dt>
|
|
<dd>Create the message queue if it does not exist.</dd>
|
|
|
|
<dt><strong>IPC_EXCL (0x00000400)</strong></dt>
|
|
<dd>Return an error if the IPC_CREAT flag is set and the message queue already exists.</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
<br>
|
|
<br>
|
|
<h3>Authorities</h3>
|
|
|
|
<p><strong><a name="TBLAMGET1">Authorization Required for
|
|
msgget()</a></strong></p>
|
|
|
|
<table border cellpadding="5">
|
|
<!-- cols="60 20 20" -->
|
|
<tr>
|
|
<th align="left" valign="bottom">Object Referred to</th>
|
|
<th align="left" valign="bottom">Authority Required</th>
|
|
<th align="left" valign="bottom">errno</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Message queue to be created</td>
|
|
<td align="left" valign="top">None</td>
|
|
<td align="left" valign="top">None</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing message queue to be accessed</td>
|
|
<td align="left" valign="top">See Note</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p><strong>Note:</strong> If the thread is accessing an existing message queue,
|
|
the mode specified in the last 9 bits of <em>msgflg</em> must be a subset of
|
|
the mode of the existing message queue.</p>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="15 85" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>value</em></td>
|
|
<td align="left" valign="top"><strong>msgget()</strong> was successful. The
|
|
value returned is the message queue identifier associated with the <em>key</em>
|
|
parameter.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>-1</em></td>
|
|
<td align="left" valign="top"><strong>msgget()</strong> was not successful. The
|
|
<em>errno</em> variable is set to indicate the error.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>msgget()</strong> is not successful, <em>errno</em> usually
|
|
indicates one of the following errors. Under some conditions, <em>errno</em>
|
|
could indicate an error other than those listed here.</p>
|
|
|
|
<dl compact>
|
|
<dt><em>[EACCES]</em></dt>
|
|
|
|
<dd>
|
|
<p>Permission denied.</p>
|
|
|
|
<p>An attempt was made to access an object in a way forbidden by its object
|
|
access permissions.</p>
|
|
|
|
<p>The thread does not have access to the specified file, directory, component,
|
|
or path.</p>
|
|
|
|
<p>A message queue identifier exists for the parameter <em>key</em>, but
|
|
permissions specified in the low-order 9 bits of <em>semflg</em>
|
|
are not a subset of the current permissions.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EDAMAGE]</em></dt>
|
|
|
|
<dd>
|
|
<p>A damaged object was encountered.</p>
|
|
|
|
<p>A referenced object is damaged. The object cannot be used.</p>
|
|
|
|
<p>The message queue has been damaged by a previous message queue
|
|
operation.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EEXIST]</em></dt>
|
|
|
|
<dd>
|
|
<p>File exists.</p>
|
|
|
|
<p>The file specified already exists and the specified operation requires that
|
|
it not exist.</p>
|
|
|
|
<p>The named file, directory, or path already exists.</p>
|
|
|
|
<p>A message queue identifier exists for the <em>key</em> parameter and both the
|
|
IPC_CREAT and IPC_EXCL flags are set in the <em>msgflg</em> parameter.
|
|
</p>
|
|
</dd>
|
|
|
|
<dt><em>[ENOENT]</em></dt>
|
|
|
|
<dd>
|
|
<p>No such path or directory.</p>
|
|
|
|
<p>The directory or a component of the path name specified does not exist.</p>
|
|
|
|
<p>A named file or directory does not exist or is an empty string.</p>
|
|
|
|
<p>A message queue identifier does not exist for the <em>key</em> parameter,
|
|
and the IPC_CREAT flag is not set in the <em>msgflg</em> parameter.</p>
|
|
</dd>
|
|
|
|
<dt><em>[ENOSPC]</em></dt>
|
|
|
|
<dd>
|
|
<p>No space available.</p>
|
|
|
|
<p>The requested operations required additional space on the device and there
|
|
is no space left. This could also be caused by exceeding the user profile
|
|
storage limit when creating or transferring ownership of an object.</p>
|
|
|
|
<p>Insufficient space remains to hold the intended file, directory, or
|
|
link.</p>
|
|
|
|
<p>A message queue identifier cannot be created because the system limit on
|
|
the maximum number of allowed message queue identifiers would be
|
|
exceeded.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EUNKNOWN]</em></dt>
|
|
|
|
<dd>
|
|
<p>Unknown system state.</p>
|
|
|
|
<p>The operation failed because of an unknown system state. See any messages in
|
|
the job log and correct any errors that are indicated, then retry the
|
|
operation.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Error Messages</h3>
|
|
|
|
<p>None.</p>
|
|
|
|
<br>
|
|
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
|
|
|
|
<ol>
|
|
<li>The best way to generate a unique key is to use the <a href="p0zftok.htm">ftok()</a>
|
|
function.</li>
|
|
|
|
</ol>
|
|
|
|
<br>
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>sys/msg.h</strong>> file (see <a href="unix13.htm">
|
|
Header Files for UNIX-Type Functions</a>)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="unix3a.htm#messagequeue">Message Queues</a> for the current system limits.
|
|
<br><br></li>
|
|
|
|
<li><a href="p0zftok.htm">ftok()</a>--Generate IPC Key from File Name<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcmsgct.htm">msgctl()</a>--Perform Message Control Operations<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcmsgrc.htm">msgrcv()</a>--Receive Message Operation<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcmsgsn.htm">msgsnd()</a>--Send Message Operation</li>
|
|
</ul>
|
|
|
|
<br>
|
|
<h3>Example</h3>
|
|
|
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
|
for information pertaining to code examples.</p>
|
|
|
|
<p>The following example creates a message queue:</p>
|
|
|
|
<pre>
|
|
#include <sys/msg.h>
|
|
#include <sys/stat.h>
|
|
|
|
main() {
|
|
int msqid;
|
|
|
|
msqid = msgget(IPC_PRIVATE, IPC_CREAT | S_IRUSR | S_IWUSR);
|
|
}
|
|
</pre>
|
|
|
|
<br>
|
|
<hr>
|
|
API introduced: V3R6
|
|
|
|
<hr>
|
|
<center>
|
|
<table cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|