Controlling shared memory
This section describes how to use
the
shmctl
system call.
The accompanying program illustrates its use.
Using shmctl
The synopsis found on the
shmctl(2)
manual page is as follows:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int shmctl (shmid, cmd, buf)
int shmid, cmd;
struct shmid_ds *buf;
The
shmctl
system call
requires three arguments to be passed to it.
It returns an integer value which will be zero
for successful completion or -1 otherwise.
The
shmid
variable
must be a valid, non-negative, integer value.
In other words, it must have already been created by
using the
shmget
system call.
The
cmd
argument can be replaced by one of
following values:
IPC_STAT-
return the status information contained
in the
associated data structure for the specified
shmid
and place it in the data structure
pointed to by the
buf
pointer in the user
memory area
IPC_SET-
for the specified
shmid,
set
the effective user and group
identification, and operation permissions
IPC_RMID-
remove the specified
shmid
with its associated shared memory segment data
structure
SHM_LOCK-
lock the specified shared memory segment
in memory; must
have P_SYSOPS privilege
to perform this operation
SHM_UNLOCK-
unlock the shared memory segment from
memory; must
have P_SYSOPS privilege
to perform this operation
To perform an
IPC_SET
or
IPC_RMID
control command,
a process must have:
-
an effective user id of OWNER/CREATOR, or
-
an effective user id of
root (if the system is running with the SUM privilege
module), or
-
the
P_OWNER
privilege.
Only root (if the SUM privilege module is installed)
can perform a
SHM_LOCK
or
SHM_UNLOCK
control command.
A process must have read permission to
perform the
IPC_STAT
control command.
The details of this system call are discussed in the example program.
If you need more information on the logic manipulations in this program, read
``Using shmget''.
It goes into more detail than would be practical for every system call.
Next topic:
Example program
Previous topic:
shmget system call example
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004