Homework 5: Using Unix System ServicesThe processes RAND_PROC1 and RAND_PROC2 now share a segment of their virtual memories. This shared segment will contain all the data structures previously managed by the STORE_MANAGER process. This brings to the problem greater efficiency and a number of complications.
Some complications are due to the fact that the process STORE_MANAGER does not
exist anymore. Thus the requests from RAND_PROC1 and RAND_PROC2 are not
serialized by the STORE_MANAGER and you have to use appropriate locks within
the code executed by RAND_PROC1 and RAND_PROC2. Since there are no pipes, all
the commands (STORE_READ and STORE_UPDATE) will be carried out as function
calls from RAND_PROC1 and RAND_PROC2, with the appropriate parameters, and
will return the appropriate values when the operation is completed.
As side effect of each call, a record will be written to the LOG.DAT file
with the following information:
Other complications arise since we are using shared memory.
To share memory among processes use the shmget, shmat, shmdt operations.
shmget creates a segment. It should be invoked with as key IPC_PRIVATE.
It should NOT be invoked in the main program.
Instead the two processes RAND_PROC1 and RAND_PROC2 should behave
symmetrically. They should agree on the name of a file and, atomically, they
should check on the existence of the file. If not there, they should create
the file, create the segment, and store its id in the file. If there, they
should read the segment id from the file.
Once a process has the id of the segment, the process attaches to it with shmat.
When done, be sure to use shmdt to delete the segment.
Often people forget to delete memory segments. Use at the shell level the commands ipcs and ipcrm to determine what shared resources are being used in the system and to remove them if no longer needed.
ingargiola@cis.temple.edu