Professor I. Rudowsky                                                                                                     CIS 25 EW6

Simulation Assignment – Phase II                                                               Due May  4, 2005

 

This phase will simulate CPU scheduling on a simple operating system. There is an infinite supply of memory to store the processes but only one process can execute on the CPU at a time – all other jobs wait on the ready queue or are blocking for I/O.

 

In order to keep track of the processes that run you will need to define a data structure to store information about each process as it enters the system and update it at various stages. Your data structure will keep track of the following information for a process:

1.          Process number (assign sequentially as it enters the system)

2.          Arrival time (in milliseconds)

3.          Process type (1, 2 or 3)

4.          Total CPU time (in milliseconds)

5.          Memory size in MB (how much memory will be required based on type)

6.          Total Waiting time (in milliseconds – all idle time excluding I/O blocking time)

7.          Number of I/O bursts

8.          Total I/O blocking time (in milliseconds)

9.          Time process completed (in milliseconds)

 

First generate a random number between 0 and 100 which provides the process type. Based on that, you will then generate the other process parameters.

  

Range

Type

CPU burst  time

Memory size

I/O bursts

I/O burst time

 

 

Min

Max

Min

Min

Max

Max

Min

Max

0-59

1

20

50

3

10

1

4

10

20

60- 79

2

30

100

10

22

3

6

45

200

80-100

3

150

500

7

43

0

2

15

50

 

Here’s how the system works: Process P0 enters the system at time 0, generates a random number between 0 and 100 to represent the process type and based on that generates memory size and the number of I/O bursts. The number of CPU bursts is one more than the number of I/O bursts. A process will always start with a CPU burst. When a CPU or I/O burst begins, its length is calculated at that point (not stored) based on the above table. When an I/O burst begins, another process gets the CPU – use FCFS as the scheduling algorithm. When a process finishes its I/O burst it goes to the end of the ready queue. When P0 enters the system, it also generates the inter-arrival time for process P1 and adds that value to the current time to get the actual arrival time of P1. While P0 is executing on the CPU or doing I/O, the arrival time of P1 may occur in which case it goes to the back of the ready queue. If P0 is doing I/O at that time, P1 will get the CPU.  When P1 arrives, its parameters are computed, the inter-arrival time for P2 is generated and its arrival time computed and stored.

 

In general, whenever a process Pj arrives its parameters are generated and the arrival time of the next process is computed. Pj will then go to the end of the ready queue and await its turn on the CPU. Each time a process gets to run on the CPU, the CPU burst time is calculated. Each time it blocks on I/O, the I/O burst time is calculated.

 

As the number of processes increases, more than one new process may arrive while an older process is executing. For each one that arrives, compute its parameters and the arrival of the next process and store them. Put the arriving process at the end of the ready queue.

 

 

Two possible ways of keeping track of time are: (a) tracking processes and checking for when a new process should start and when the current processes on CPU and or I/O end or (b) using a loop and treating each iteration as a millisecond and checking at each millisecond what process is running on the CPU, which is doing I/O and which is the next one to run. Do this by hand for a small example to get the flow of events – use an example where new arrivals occur while a process is executing

 

(1) Run this simulation until 10 processes have completed. Use a value of 200 for initVal when generating interarrival times.

 

Do not be concerned if two processes have the same arrival time (i.e., a process has an interarrival time of 0). Since we are processing sequentially, the earlier one will be handled  first.

 

(a)   After each individual process completes, print the following detail information. Note that processes may not finish in sequential order.

 

FCFS simulation detail with InitVal = XXXX

Process

Type

Interarrival time

CPU time

Arrival time

Memory size

Start time

Wait time

I/O Bursts

I/O Blocking time

Time Completed

 

 

 

 

 

 

 

 

 

 

 

 

 

(b)   When all 10 processes have completed, print out by type the following statistics

 

        FCFS simulation summary by process type with InitVal = XXXX

Process Type

Number of processes

Avg CPU Time

Avg memory size

Avg wait time

Avg I/O bursts

Avg I/O blocking time

1

 

 

 

 

 

 

2

 

 

 

 

 

 

3

 

 

 

 

 

 

Overall

XXXXXXX

 

 

 

 

 

 

 (2) Run the same simulation but stop after 1,000 processes have completed, use InitVal of 100

(a)  Print the summary by process type report

 

You must document your code either in the program itself or in a separate attachment. Explain clearly how your code implements each scheduling algorithm – how you keep track of time, your data structures for storing processes, how you move processes to and from the CPU, etc. Without this documentation, you will lose points.