System Architecture 2-27
How User Processes Attach to Shared Memory
The user process lays out the first shared-memory segment, which includes
the shared-memory header. Sixteen bytes into the header, the user process
obtains the following data:
The total size of shared memory for this OnLine server
The size of each shared-memory segment
The user process then calculates how much shared memory it has and how
much is still required. (Each user process must acquire the total amount of
shared memory.)
Step 5: Attach Additional Segments
Ifone or more shared-memory segments are required, the user processmakes
anadditional request to the UNIX operating system. To obtain the key value
forthe shared-memory segment that it needs, the user process adds the value
1 to the previous value ofshmkey. (Given the initial calculation of
(SERVERNUM* 65536) + shmkey, this means that any OnLine server can
request up to 65,536 shared-memory segments before the possibility arises
that one OnLine system could request a shared-memory key value used by
another OnLine system.)
Justas before, the user process transfers the key value to UNIX, which returns
ashared-memory identifier. The user process directs the operating system to
attach the segment at the address defined by the relation:
SHMBASE + (seg_size x number of attached segments)
(If your operating system uses a parameter to define the lower boundary
address, and this parameter is set incorrectly, it can prevent the shared-
memory segments from being attached contiguously. Refer topage 2-20 for
more information aboutUNIX parameters and attaching to shared memory.)
After the new shared-memory segment is attached, the user process again
compares the total size of shared memory with the amount of shared
memory now attached. If additional memory is needed, the user process
recalculates the next shared-memory key value and requests the associated
shared-memory segment from UNIX. This process repeats until the user
process has acquired the total amount of shared memory.