ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/ipcshmct.htm

456 lines
14 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>shmctl()-Perform Shared Memory Control Operations</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>shmctl()--Perform Shared Memory Control Operations</h2>
<div class="box" style="width: 80%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/shm.h&gt;
int shmctl(int <em>shmid</em>, int <em>cmd</em>, struct shmid_ds <em>*buf</em>);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0ZUSHR<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>shmctl()</strong> function allows the caller to control
the shared memory segment specified by the <em>shmid</em> parameter.</p>
<p>A shared memory segment is controlled by setting the <em>cmd</em> parameter
to one of the following values:
<dl>
<dt><strong>IPC_RMID (0x00000000)</strong></dt>
<dd>Remove the shared memory segment identifier <em>shmid</em> from the system and
destroy the shared memory segment.
<p>The IPC_RMID command can be run only by a thread with appropriate privileges
or one that has an effective user ID equal to the user ID of the owner or the user ID
of the creator of the shared memory segment. The
structure pointed to by <em>*buf</em> is ignored and can be NULL.</p>
</dd>
<dt><strong>IPC_SET (0x00000001)</strong></dt>
<dd>Set the user ID of the owner, the group ID of the owner, the permissions, and the
maximum number of bytes for the shared memory segment to the values in the
<samp>shm_perm.uid</samp>, <samp>shm_perm.gid</samp>, and
<samp>shm_perm.mode</samp> members of the
<samp>shmid_ds</samp> data structure pointed to by <em>*buf</em>.
<p>The IPC_SET command can be run only by a thread with appropriate privileges or one that
has an effective user ID equal to the user ID of the owner or the user ID
of the creator of the shared memory segment.</p>
</dd>
<dt><strong>IPC_STAT (0x00000002)</strong></dt>
<dd>Store the current value of each member of the
<samp>shmid_ds</samp> data structure into the
structure pointed to by <em>*buf</em>. The IPC_STAT command requires read
permission to the shared memory segment.<p></dd>
<dt><strong>SHM_SIZE (0x00000006)</strong></dt>
<dd>Set the size of the shared memory segment using the <samp>shm_segsz</samp>
member of the <samp>shmid_ds</samp> data structure pointed to by
<em>*buf</em>. This value may be larger or smaller than the current size. This
command is valid for nonteraspace shared memory segments and for teraspace
shared memory segments created using the SHM_RESIZE_NP option of the <strong>
shmget()</strong> function. The maximum size to which a nonteraspace shared memory
segment may be expanded is 16&nbsp;773&nbsp;120 bytes (16 MB minus 4096 bytes).
The maximum size of a resizeable teraspace shared memory segment is
268&nbsp;435&nbsp;456 bytes (256 MB).
<br>
The SHM_SIZE command can be run only by a
thread with appropriate privileges or a thread that has an effective user ID
equal to the user ID of the owner or the user ID
of the creator of the shared memory segment.
<br>
If a shared memory segment is resized to a smaller size, other threads using
the memory that is being removed from the shared memory segment may
experience memory exceptions when accessing that memory.
</dd>
</dl>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>shmid</strong></dt>
<dd>(Input) Shared memory identifier, a positive integer. It is returned by the
<a href="ipcshmgt.htm">shmget()</a> function and used to identify the shared memory
segment on which to perform the control operation.<br>
<br>
</dd>
<dt><strong>cmd</strong></dt>
<dd>(Input) Command, the control operation to perform on the shared memory
segment. Valid values are listed above.<br>
<br>
</dd>
<dt><strong>buf</strong></dt>
<dd>(I/O) Pointer to the <samp>shmid_ds</samp> structure to be used to get or
set shared memory information.
<p>The members of the <samp>shmid_ds</samp> structure are as follows:</p>
</dd>
</dl>
<table cellpadding="5">
<!-- cols="15 85" -->
<tr>
<td align="left" valign="top"><em>struct ipc_perm shm_perm</em> </td>
<td align="left" valign="top">The members of the <samp>ipc_perm</samp> structure
are as follows:
<table cellpadding="5">
<tr>
<td align="left" valign="top"><em>uid_t uid</em> </td>
<td align="left" valign="top">The user ID of the owner of the segment.</td>
</tr>
<tr>
<td align="left" valign="top"><em>gid_t gid</em> </td>
<td align="left" valign="top">The group ID of the owner of the segment.</td>
</tr>
<tr>
<td align="left" valign="top"><em>uid_t cuid</em> </td>
<td align="left" valign="top">The user ID of the creator of the segment.</td>
</tr>
<tr>
<td align="left" valign="top"><em>gid_t cgid</em> </td>
<td align="left" valign="top">The group ID of the creator of the segment.</td>
</tr>
<tr>
<td align="left" valign="top"><em>mode_t mode</em> </td>
<td align="left" valign="top">The permissions for the segment.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>size_t shm_segsz</em> </td>
<td align="left" valign="top">The size of the segment in bytes.</td>
</tr>
<tr>
<td align="left" valign="top"><em>pid_t shm_lpid</em> </td>
<td align="left" valign="top">The process ID of the last job to attach or detach
to the segment using <strong>shmat()</strong> or <strong>shmdt()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>pid_t shm_cpid</em> </td>
<td align="left" valign="top">The process ID of the job that created the segment
using <strong>shmget()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>int shm_nattch</em> </td>
<td align="left" valign="top">The number of jobs attached to the segment.</td>
</tr>
<tr>
<td align="left" valign="top"><em>time_t shm_atime</em> </td>
<td align="left" valign="top">The time the last job attached to the segment
using <strong>shmat()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>time_t shm_dtime</em> </td>
<td align="left" valign="top">The time the last job detached from the segment
using <strong>shmdt()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>time_t shm_ctime</em> </td>
<td align="left" valign="top">The time the last job changed the segment using
<strong>shmctl()</strong>.</td>
</tr>
</table>
<br>
<br>
<h3>Authorities</h3>
<p><strong><a name="TBLAHCTL1">Authorization Required for
shmctl()</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">Shared memory segment for which state information
is retrieved (<em>cmd</em> = IPC_STAT)</td>
<td align="left" valign="top">Read</td>
<td align="left" valign="top">EACCES</td>
</tr>
<tr>
<td align="left" valign="top">Shared memory segment for which state information
is set (<em>cmd</em> = IPC_SET)</td>
<td align="left" valign="top">See Note</td>
<td align="left" valign="top">EPERM</td>
</tr>
<tr>
<td align="left" valign="top">Shared memory segment to be removed
(<em>cmd</em> = IPC_RMID)</td>
<td align="left" valign="top">See Note</td>
<td align="left" valign="top">EPERM</td>
</tr>
<tr>
<td align="left" valign="top">Shared memory segment to be resized
(<em>cmd</em> = SHM_SIZE)</td>
<td align="left" valign="top">See Note</td>
<td align="left" valign="top">EPERM</td>
</tr>
</table>
<p><strong>Note:</strong> To set shared memory segment information, to remove a
shared memory segment, or to resize a shared memory segment, the thread must be
the owner or creator of the shared memory segment or have appropriate
privileges.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="5 95" -->
<tr>
<td align="left" valign="top"><em>0</em></td>
<td align="left" valign="top"><strong>shmctl()</strong> was successful.</td>
</tr>
<tr>
<td align="left" valign="top" nowrap><em>-1</em></td>
<td align="left" valign="top"><strong>shmctl()</strong> was not successful. The
<em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<br>
<h3>Error Conditions</h3>
<p>If <strong>shmctl()</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>
<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>The <em>cmd</em> parameter is IPC_STAT and the calling thread
does not have read permission to shared memory segment.</p>
</dd>
<dt><em>[EDAMAGE]</em></dt>
<dd>
<p>A damaged object was encountered.</p>
<p>The shared memory segment has been damaged by a previous shared memory
operation.</p>
</dd>
<dt><em>[EFAULT]</em></dt>
<dd>
<p>The address used for an argument is not correct.</p>
<p>In attempting to use an argument in a call, the system detected an address
that is not valid.</p>
<p>While attempting to access a parameter passed to this function, the system
detected an address that is not valid.</p>
</dd>
<dt><em>[EINVAL]</em></dt>
<dd>
<p>The value specified for the argument is not correct.</p>
<p>A function was passed incorrect argument values, or an operation was
attempted on an object and the operation specified is not supported for that
type of object.</p>
<p>An argument value is not valid, out of range, or NULL.</p>
<p>One of the following has occurred:</p>
<ul>
<li>The <em>shmid</em> parameter is not a valid shared memory identifier.</li>
<li>The <em>cmd</em> parameter is not a valid command.</li>
<li>The <em>cmd</em> parameter is SHM_SIZE, and the teraspace shared memory
segment cannot be resized because it was not created by specifying
SHM_RESIZE_NP on the <em>shmflg</em> parameter of <strong>
shmget()</strong>.</li>
<li>The <em>cmd</em> parameter is SHM_SIZE, and the new size is not
valid for the shared memory segment.</li>
</ul><br>
</dd>
<dt><em>[ENOMEM]</em></dt>
<dd>
<p>Storage allocation request failed.</p>
<p>A function needed to allocate storage, but no storage is available.</p>
<p>A shared memory identifier segment is to be resized, but the amount of
available physical memory is not sufficient to fulfill the request.</p>
</dd>
<dt><em>[EPERM]</em></dt>
<dd>
<p>Operation not permitted.</p>
<p>You must have appropriate privileges or be the owner of the object or other
resource to do the requested operation.</p>
<p>The <em>cmd</em> parameter is IPC_RMID or IPC_SET and both of the
following are true:</p>
<ul>
<li>the calling thread does not have the appropriate privileges.</li>
<li>the effective user ID of the calling thread is not equal to the user ID
of the owner or the user ID of the creator of the shared memory segment.</li>
</ul><br>
</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>&quot;Appropriate privileges&quot; is defined to be *ALLOBJ special authority. If the
user profile under which the thread is running does not have *ALLOBJ special
authority, the thread does not have appropriate privileges.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>sys/shm.h</strong>&gt; file (see <a href="unix13.htm">
Header Files for UNIX-Type Functions</a>)<br>
<br>
</li>
<li><a href="ipcshmat.htm">shmat()</a>--Attach Shared Memory Segment to Current
Process<br>
<br>
</li>
<li><a href="ipcshmdt.htm">shmdt()</a>--Detach Shared Memory Segment from
Calling Process<br>
<br>
</li>
<li><a href="ipcshmgt.htm">shmget()</a>--Get ID of Shared Memory Segment with
Key</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>For an example of using this function, see <a href="../apiref/apiexusmem.htm">
Using Semaphores and Shared Memory</a> in Examples: APIs.</p>
<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>