The Linux Programming Interface

(nextflipdebug5) #1
System V Shared Memory 1007

Figure 48-2: Locations of shared memory, memory mappings, and shared libraries (x86-32)


In the shell session below, we employ three programs that are not shown in this
chapter, but are provided in the svshm subdirectory in the source code distribution
for this book. These programs perform the following tasks:


z The svshm_create.c program creates a shared memory segment. This program
takes the same command-line options as the corresponding programs that we
provide for message queues (Listing 46-1, on page 938) and semaphores, but
includes an additional argument that specifies the size of the segment.


z The svshm_attach.c program attaches the shared memory segments identified by
its command-line arguments. Each of these arguments is a colon-separated pair
of numbers consisting of a shared memory identifier and an attach address.
Specifying 0 for the attach address means that the system should choose the
address. The program displays the address at which the memory is actually
attached. For informational purposes, the program also displays the value of
the SHMLBA constant and the process ID of the process running the program.


z The svshm_rm.c program deletes the shared memory segments identified by its
command-line arguments.


Shared memory, memory
mappings, and shared
libraries placed here

Reserved for heap expansion

Virtual memory address
(hexadecimal)

argv, environ

Uninitialized data (bss)
Initialized data
Text (program code)

0xC0000000

Stack

Heap

0x08048000

0x40000000
TASK_UNMAPPED_BASE

Top of
stack

Program
break

increasing virtual addesses0x00000000
Free download pdf