shmctl(2) DG/UX 4.30 shmctl(2)
NAME
shmctl - Shared memory control operations.
SYNOPSIS
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int shmctl (shmid, cmd, buf)
int shmid;
int cmd;
struct shmid_ds * buf;
PARAMETERS
shmid The shared memory identifier of the shared
area to be operated on.
cmd The specific shared memory operation.
Supported operations are IPC_STAT, IPC_SET,
and IPC_RMID.
buf The address of a shared memory structure to
be used in the operation. Used only if
command is IPC_STAT or IPC_SET.
DESCRIPTION
The shmctl system call is used to obtain or modify
information on shared memory segments previously defined by
shmget. The shmctl call also allows for the destruction of
shared memory segments. The action performed by shmctl is
determined by the value of the cmd 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 buf.
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
buf are undefined.
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 buf. Only the following fields may be set:
shm_perm.uid
shm_perm.gid
Licensed material--property of copyright holder(s) Page 1
shmctl(2) DG/UX 4.30 shmctl(2)
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 a 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; that is,
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
The access required to the shared memory segment denoted by
shmid depends on the value of cmd, 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 cmd 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
Licensed material--property of copyright holder(s) Page 2
shmctl(2) DG/UX 4.30 shmctl(2)
shm_perm field of the shared memory data structure
associated with shmid.
IPC_RMID
Remove shared memory identifier. This cmd 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 cmd:
EINVAL Shmid is not a valid shared memory
identifier; or cmd is not a valid command.
The IPC_STAT command may return the following errors:
EFAULT buf points to an illegal address.
EACCES Read access is denied.
The IPC_SET command may return the following errors:
EFAULT buf points to an illegal address.
EPERM Access is denied; that is, 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
intro(2), ipcrm(1), ipcs(1), shmget(2).
Licensed material--property of copyright holder(s) Page 3