CIS 307: Homework 4 (Hints)

Using Unix System Services (shared memory, file locks). Given November 7, due November 13

This homework is the continuation of Homework 3. It will have the same behavior, but changed implementation. Now we will not have the STORE_MANAGER process.

The 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, a number of complications, and a great simplification.

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 CHILDprocid.DAT file with the following information:
TIME_STAMP: Time information; OPERATION: [R, U]; PARAMETERS: The parameters of the call

To create critical regions use file locking (lockf). Use a separate lock for each entry of the store (use a single file with the different locks represented by different records).

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.

There is a great simplification in this homework with respect to homework 3. Now the work on the store is done directly by the clients. Thus the fact that we are dealing with slow operations does not require us to manage in the store-manager an agenda (a priority queue). Instead the clients themselves start the operations, sleep, wake up at completion, and continue.

ingargiola@cis.temple.edu