O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Shared Memory

Once the shared memory is attached, your process can use it like any other region of memory. However, since multiple processes can see this same region of memory, care must be exercised when changing its content.

In the globvar utility, one semaphore is used as the locking semaphore. Whenever the shared memory is searched or modified, the globvar utility waits on the semaphore first (recall that it was initialized to the value of 1). This ensures that no more than one process at a time will be working with the shared memory. When the task has been completed, the semaphore is notified to release the lock.

It should be noted that some values were accessed in the shared memory without the locking semaphore. Examine lines 15–19 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required