System V Shared Memory
In the Oracle Solaris 11 operating system, the efficient way to implement shared
memory applications is to rely on mmap
()
and on the
system's native virtual memory facility. For more information, see
Memory and CPU Management and the
mmap
(2) man page.
The Oracle Solaris 11 platform also supports System V shared memory, which is a less efficient way to enable the attachment of a segment of physical memory to the virtual address spaces of multiple processes. When write access is allowed for more than one process, an outside protocol or mechanism, such as a semaphore, can be used to prevent inconsistencies and collisions.
A process creates a shared memory segment using
shmget
(). This call is also used to get the ID of an
existing shared segment. The creating process sets the permissions and
the size in bytes for the segment.
The original owner of a shared memory segment can assign
ownership to another user with shmctl
(). The owner
can also revoke this assignment. Other processes with proper permission
can perform various control functions on the shared memory segment using
shmctl
().
Once created, you can attach a shared segment to a process
address space using shmat
(). You can detach it using
shmdt
(). The attaching process must have the appropriate permissions for shmat
(). Once attached,
the process can read or write to the segment, as allowed by the
permission requested in the attach operation. A shared segment can be
attached multiple times by the same process.
A shared memory segment is described by a control structure with a
unique ID that points to an area of physical memory. The identifier
of the segment is called the shmid
. You can find
the structure definition for the shared memory segment control in
sys/shm.h
.
For more information, see the
shmget
(2),
shmctl
(2),
shmat
(2),
and
shmdt
(2) man pages.