shmctl(2)
_________________________________________________________________
shmctl System Call
Shared memory control operations.
_________________________________________________________________
SYNTAX
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int shmctl (shmid, command, shmid_buffer)
int shmid;
int command;
struct shmid_ds * shmid_buffer;
PARAMETERS
shmid The shared memory identifier of the shared area to
be operated on.
command The specific shared memory operation. Supported
operations are IPC_STAT, IPC_SET, and IPC_RMID.
shmid_buffer The address of a shared memory structure to be
used in the operation. Used only if command is
IPC_STAT or IPC_SET.
DESCRIPTION
Shmctl is used to obtain or modify information on shared memory
segments previously defined by shmget. Shmctl also allows for
the destruction of shared memory segments. The action performed
by shmctl is determined by the value of the <command> parameter
as described below.
IPC_STAT
Get status information.
Returns the current value of each member of the shared
memory data structure (shmid_ds) associated with the shared
memory segment specified by <shmid> into the buffer pointed
to by <shmid_buffer>. This command does not change the
values of any of the fields in the shared memory data
structure. If an error occurs, the contents of the buffer
pointed to by <shmid_buffer> are undefined.
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
shmctl(2)
IPC_SET
Set status information.
Set the current value of each member of the shared memory
data structure (shmid_ds) associated with the shared memory
segment specified by <shmid> to the corresponding value in
the buffer pointed to by <shmid_buffer>. Only the following
fields may be set:
shm_perm.uid
shm_perm.gid
shm_perm.mode /* only low 9 bits */
In addition to setting the above fields, this command causes
the shm_ctime field to be set to the current time. If an
error occurs, no changes are made to any of the fields in
the shared memory descriptor.
IPC_RMID
Remove shared memory identifier.
This "deletes" the shared memory identifier specified by
<shmid> from the system. This command has "delete on last
detach" semantics. The shared area segment is not actually
destroyed until all processes that currently have the area
attached detach from it via the shmdt operation. However,
no other processes may attach to the shared area via the
shmat call. (Note, however, that implicit attach operations
that occur as part of a fork operation may still occur; see
shmat.) Once this command is performed on an <shmid>, the
only operations that may be performed on that <shmid> are
the IPC_STAT command of shmctl and the shmdt operation. All
other operations act as though <shmid> is invalid; i.e.,
return the EINVAL status code. A shared segment that has
had this operation performed on it will have the SHM_DEST
bit set in the shm_perm.mode field of its shared memory data
structure. (This information is returned by the IPC_STAT
command of shmctl.) This command updates the shm_ctime field
in the shared segment's data structure to the current time.
If an error occurs, the shared segment is not deleted and no
changes are made to its shared memory data structure.
Note that none of the commands require that the caller have the
shared segment attached.
ACCESS CONTROL
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
shmctl(2)
The access required to the shared memory segment denoted by
<shmid> depends on the value of <command>, as specified below.
IPC_STAT
Get status information.
The effective user id of the calling process must equal the
superuser; or the calling process must have read access
(SHM_R) as determined by the mode bits in the ipc_perm
structure defined by the shm_perm field of the shared memory
data structure associated with <shmid>.
IPC_SET
Set status information.
This <command> can be executed by any process with effective
user id equal to either that of superuser; or to the value
of either shm_perm.uid or shm_perm.cuid in the ipc_perm
structure defined by the shm_perm field of the shared memory
data structure associated with <shmid>.
IPC_RMID
Remove shared memory identifier.
This <command> can be executed by any process with effective
user id equal to either that of superuser; or to the value
of either shm_perm.uid or shm_perm.cuid in the ipc_perm
structure defined by the shm_perm field of the shared memory
data structure associated with <shmid>.
RETURN VALUE
0 The shmctl operation was successful.
-1 An error occurred. Errno is set to indicate the
error.
EXCEPTIONS
Errno may be set to one of the following error codes for any
value of <command>:
EINVAL <Shmid> is not a valid shared memory identifier.
EINVAL <Command> is not a valid command.
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)
shmctl(2)
The IPC_STAT command may return the following errors:
EFAULT <Shmid_buffer> points to an illegal address.
EACCES Read access is denied.
The IPC_SET command may return the following errors:
EFAULT <Shmid_buffer> points to an illegal address.
EPERM Access is denied; i.e., effective user id of the
calling process is not superuser and does not
match the shm_perm.uid or shm_perm.cuid fields of
the shared memory descriptor associated with
<shmid>.
The IPC_RMID command may return the following error:
EPERM The caller is not a superuser and the effective
user id does not match the uid or cuid of the
segment.
SEE ALSO
The related system calls: intro, shmget, shmop.
DG/UX 4.00 Page 4
Licensed material--property of copyright holder(s)