Attaching and Detaching a Shared Memory Segment

shmat() and shmdt() (see shmop(2)) are
used to attach and detach shared memory segments. shmat(2) returns a pointer to the head
of the shared segment. shmdt(2)
detaches the shared memory segment located at the address indicated by shmaddr. The following code illustrates calls to shmat(2) and shmdt(2):