Homework 4: Using Unix System ServicesSTORE_MANAGER receives messages from RAND_PROC1 and RAND_PROC2 through the pipe C_BOX. It responds to messages from RAND_PROC1 by placing the responses in the pipe RAND_BOX1. It responds to messages from RAND_PROC2 by placing the responses in RAND_BOX2. Each message is time-stamped and recorded in the file 'LOG.DAT' shared for write append by the child processes RAND_BOX1, RAND_BOX2.
The STORE_MANAGER keeps in a STORE a number of pairs (SSTORE_ID, SSTORE_ELEM); you choose an initial list of pairs. SSTORE_ID and SSTORE_ELEM are strings of up to 20 characters. For example, SSTORE_ID represents a host name (say, snowhite.cis.temple.edu) and SSTORE_ELEM represents the corresponding UID (say, 155.247.190.1). The STORE carries out two operations SSTORE_UPDATE and SSTORE_READ.
function SSTORE_UPDATE (WHO : SSTORE_ID;
WHAT : SSTORE_ELEM) return INTEGER;
{It updates the value of WHO to be WHAT. It returns 0 iff successful}
{Note that WHO denotes the pair with first element equal to WHO.}
function SSTORE_READ (WHO : SSTORE_ID;
var WHAT : SSTORE_ELEM) return INTEGER;
{It retrieves the value of WHO and stores it in WHAT.
It returns 0 iff successful}
STORE_MANAGER receives messages that consist of, in sequence:
o An Origin Code ['1' for RAND_PROC1, '2' for RAND_PROC2] o A message code ['U' for SSTORE_UPDATE, 'G' for SSTORE_READ] o The operands required by the corresponding operation [hence for SSTORE_UPDATE, the 'U' will be followed by a SSTORE_ID value and by a SSTORE_ELEM value, while for SSTORE_READ, the 'G' will be followed only by SSTORE_ID.]
The STORE_MANAGER responses consist of the character representing the operation requested, followed by the result of the operation ['0' for success, '1' for failure], followed by the values involved in the operation [both SSTORE_ID and SSTORE_ELEM].
RAND_PROC1 and RAND_PROC2 have the same form [but use different seeds!]:
RAND_PROCi: loop
generate a random SSTORE_READ or SSTORE_UPDATE request;
[in both operations the SSTORE_ID should be selected
at random from a list maintained at RAND_PROCi; in the
SSTORE_UPDATE operation SSTORE_ELEM should be created using
a random number generator]
wait for and log to 'LOG.DAT' the corresponding response;
wait some random time;
end loop
In writing RAND_PROCi you should represent the sending of a message
and the receiving of the corresponding response within calls to the
following functions:
function SSTORE_UPDATE (WHO : SSTORE_ID;
WHAT : SSTORE_ELEM) return INTEGER;
{It updates the value of WHO to be WHAT. It returns 0 iff successful}
{Note that WHO denotes the pair with first element equal to WHO.}
function SSTORE_READ (WHO : SSTORE_ID;
var WHAT : SSTORE_ELEM) return INTEGER;
{It retrieves the value of WHO and stores it in WHAT.
It returns 0 iff successful}
As you may have noticed, I have used the same name and form for the
functions used in
the STORE_MANAGER to access STORE, and in the processes RAND_PROC1 and
RAND_PROC2 to communicate with STORE_MANAGER. I did it intentionally to
stress that through communication the STORE is as if it were local to
its users.
Write RAND_PROC1 to always use a string of 1s as update value in calls to SSTORE_UPDATE. RAND_PROC2 will instead use a string of 2s.
HMW_MAIN, after starting the other processes, in a loop prompts the users to ask if they want to see statistical information from RAND_PROC1 and RAND_PROC2.
ingargiola@cis.temple.edu