Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


CP 386, Fall 2021

Assignment 1 (10% of the final grade)


        Your task is to implement a simplified Dispatcher for an OS. It will react to events and change states of processes admitted to the system respectfully, as described in lecture notes and the textbook. Events will be simulated. The sequence of events will be given in the standard input (one event per line). Empty line will signify the end of the input. Format of one line is as follows:

where

<time> is an integer number denoting local time in milliseconds measured from 0 (time will be strictly increasing from line to line);

<event> is one of the following:

– C - create

– E - exit

– R N - request resource number N

– I N - interrupt from resource number N (request accomplished)

– T - timer interrupt

<process id> is a nonnegative integer, unique for each process (system idle process has <process id> = 0);

Here is an example of several first lines of the input (comments are here for explanation only):

        Your Dispatcher will have to keep track of events and changes in the state of the processes, taking into account the following additional conditions:

there are 3 different kinds of resources in the system and requests can be serviced out of order of arrival;

there is time sharing, so the process which is in running state is to be preempted as the result of the timer interrupt if there are other ready processes in the system;

running process can also exit or get blocked because of request for a resource;

if there are no ready user processes, then process number 0 (system idle process) is running;

if process 0 is running and new process is created, or as the result of an event one of the blocked processes becomes ready (unblocked), this process will get CPU immediately.

When all lines of the input are processed, Dispatcher will print the following cumulative information about all processes admitted to the system during simulation (in the increasing order of process IDs):

For the system idle process print only <total time Running> and assume that process 0 was created at time 0.

        For example for the input

expected output is

        You can assume that the sequence of events given in input is consistent. However, do not assume that process IDs start with 1 and are consecutive numbers. It is possible that simulation uses process IDs, for example, 12, 124 and 7.

        Submit your implementation in file Dispatcher.java. Do not use any additional files. If you need helper classes for implementation, use inner classes.

        It should be possible to compile your program with javac Dispatcher.java in command line window. Which means that submitted Java file must use “default” package (no package keyword!!!).

        Your program will read multi-line events description from the standard input and will print required statistics to the standard output. DO NOT PRINT ANY PROMPTS FOR THE INPUT!