Open System Services System Calls Reference Manual (G06.25+, H06.03+)
System Functions (s and S) shmget(2)
• It allows detection of attempts to reference shared memory segments in other processors.
Key Creation
The key represents a user-designated name for a given shared memory segment. Keys are usu-
ally selected by calling the ftok( ) function before calling the shmget() function. The ftok( )
function returns a key based on a path and an interprocess communications identi
fier. This key is
then passed to the shmget() function, which returns a shared memory identifier. The shared
memory identifier is then used in calls to the shmat() and shmctl() functions.
Uniqueness of Identifiers
The system recycles no-longer-used shared memory identi
fiers after a long time elapses.
Swap File
A shared memory segment is shared through a Guardian environment swap file so that its data
remains intact even when no processes include it in their virtual address space. This swap file is
temporary. It resides on the local HP NonStop node on the same volume as the swap file for the
stack segment of the process creating the shared memory segment. If the stack segment is
resident, the code segment of the process is used instead.
Processor or Disk Process Failures
If a processor fails, the following is lost:
• All information in the system-maintained shared memory table for that processor
• All shared memory segments for that processor
• All corresponding swap files
If the disk process controlling the swap file fails, the system monitor causes any process with the
corresponding shared memory attached to terminate abnormally. Thereafter, a process cannot
successfully call either the shmget() or shmat() function using the associated shared memory
identifier. When either function is called, the shared memory segment and its identifier are
removed from the system-maintained shared memory table.
Valid Segment Sizes
A shared memory segment can contain up to 4 regions. A region is 32 megabytes (MB). A
shared memory segment can therefore be 1 byte to 128 MB in size.
Number of Shared Segments and Identifiers
The maximum number of shared memory identifiers is determined by the maximum number of
processes allowed for the processor. This value cannot exceed the limit
SHMT_MAXENTRIES, which is currently set to 1000.
Cleaning Up Shared Memory Identifiers
A shared memory identifier remains allocated until it is removed. An allocated shared memory
identifier is not removed when the last process using it terminates. The user must remove allo-
cated shared memory identifiers that are not attached to processes to avoid wasting shared
memory resources.
The status of shared memory identifiers can be checked with the ipcs command. Shared memory
identifiers can be removed using the ipcrm command. The associated shared memory segment
and data structure are removed only after the final detach operation.
Shared Memory Use Between Environments
Guardian environment processes cannot use OSS environment function calls for access to OSS
shared memory segments. Similarly, OSS environment processes cannot use OSS environment
function calls for access to Guardian environment shared memory segments. However, OSS
environment processes can allocate a Guardian environment shared memory segment and mani-
pulate it using Guardian environment procedure calls. A Guardian environment process and an
OSS environment process can share resources through the Guardian environment shared
527186-003 Hewlett-Packard Company 7−55