In computer programming, shared memory is a method
by which program process can exchange data more quickly than by reading
and writing using the regular operating system services. For example,
a client process may have data to pass to a server process that the server
process is to modify and return to the client. Ordinarily, this would
require the client writing to an output file (using the buffer of the
operating system) and the server then reading that file as input from
the buffer to its own work space. Using a designated area of shared memory,
the data can be made directly accessible to both processes without having
to use the system services. To put the data in shared memory, the client
gets access to shared memory after checking a semaphore value, writes
the data, and then resets the semaphore to signal to the server (which
periodically checks shared memory for possible input) that data is waiting.
In turn, the server process writes data back to the shared memory area,
using the semaphore to indicate that data is ready to be read.
|