shmctl
Purpose
Controls shared memory operations.
Syntax
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int shmctl (shmid, cmd, buf)
int shmid, cmd;
struct shmid_ds *buf;
Description
The shmctl system call performs a variety of shared
memory control operations as specified by the cmd param-
eter. The shmid parameter is a shared memory identifier
returned by the shmget system call. The following cmds
are available:
IPC_STAT Places the current value of each member of
the data structure associated with the shmid
parameter into the shmid_ds structure pointed
to by the buf parameter. The current process
must have read permission in order to perform
this operation. The shmid_ds structure is
defined in the sys/shm.h header file, and it
contains the following members:
struct ipc_perm shm_perm; /* Operation permission structure */
int shm_segsz; /* Segment size */
ushort shm_segid; /* Segment identifier */
ushort shm_lpid; /* ID of last process to call shmop */
ushort shm_cpid; /* ID of process that created this shmid */
ushort shm_nattch; /* Current number of processes attached */
ushort shm_cnattach; /* No. of in-memory processes attached */
time_t shm_atime; /* Time of last shmat call */
time_t shm_dtime; /* Time of last shmdt call */
time_t shm_ctime; /* Time of the last change to this */
/* structure with a shmctl call */
IPC_SET Sets the value of the following members of
the data structure associated with the shmid
parameter to the corresponding value found in
the structure pointed to by the buf param-
eter:
shm_perm.uid
shm_perm.gid
shm_perm.mode /* Only the low-order nine bits */
This cmd can only be performed by a process
that has an effective user ID equal to either
that of superuser or to the value of
shm_perm.uid in the data structure associated
with the shmid parameter.
IPC_RMID Removes the shared memory identifier speci-
fied by the shmid parameter from the system
and erases the shared memory segment and data
structure associated with it. This cmd can
only be executed by a process that has an
effective user ID equal to either that of
superuser or to the value of shm_perm.uid in
the data structure associated with the shmid
parameter.
SHM_SIZE Sets the size of the shared memory segment to
the value specified by buf->shm_segsz. This
value can be larger or smaller than the
current size, as long as it is not greater
than the value of the shmmax keyword set in
the /etc/master file. This cmd can only be
executed by a process that has an effective
user ID equal to either that of superuser or
to the value of shm_perm.uid in the data
structure associated with the shmid param-
eter.
Return Value
Upon successful completion, a value of 0 is returned. If
shmctl fails, a value of -1 is returned and errno is set
to indicate the error.
Diagnostics
The shmctl system call fails if one or more of the fol-
lowing are true:
EINVAL The shmid parameter is not a valid shared
memory identifier.
EINVAL The cmd parameter is not a valid command.
EINVAL The cmd parameter is equal to SHM_SIZE and
buf->shm_segsz is greater than the value of
the shmmax keyword in the /etc/master file.
EACCES The cmd parameter is equal to IPC_STAT and
read permission is denied to the calling
process.
EPERM The cmd parameter is equal to IPC_RMID,
IPC_SET, or SHM_SIZE, and the effective user
ID of the calling process is neither equal to
the superuser ID, nor is it equal to the value
of shm_perm.uid in the data structure associ-
ated with shmid.
ENOMEM The cmd parameter is equal to SHM_SIZE and the
attempt to change the segment size failed.
EFAULT The buf parameter &pointsout..
Related Information
In this book: "disclaim," "shmat," "shmdt," "shmget,"
and "master."