Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Objectives: Demonstrate a working knowledge of cpu scheduling algorithms Investigate the pros and cons of each algorithm A simulation mimics the execution of n

Assignment Objectives:

Demonstrate a working knowledge of cpu scheduling algorithms Investigate the pros and cons of each algorithm A simulation mimics the execution of n different processes under different scheduling algorithms. The simulation maintains a table that reflects the current state of the system: Process ID Active Arrival time Total CPU time Remaining CPU time Turnaround time ... p 0/1 A T R TT ... The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of selecting the processs to run and updating the time remaining for that process.

Part 1:

Command Line Usage

Write a c program that reads parameters from the command line. The simulator needs to accept the following parameters: n - the number of processes to simulate k - the maximum time step when a process can be created min_time - the minimum time a process needs to run max_time - the maximum time a process needs to run For simplicity these can be simple positional parameters (use the following above order) or you can use a more complex parameter parsing techniques. If the program is run with missing or incorrect parameters print a help message that indicates the proper usage. If the program is run without any parameters you should use the following default values: n = 10 k = 100 min_time =7 max_time= 15

Part 2:

Simulation Setup

Using the parameters entered on the command line (or the default values if no parameters were provided) create and initialize the simulation table. The table is initialized as follows: The field "active" indicates whether the process is currently competing for the CPU. The value becomes 1 at the time of process arrival and 0 at the time of process termination. Initially, the value is set to 1 for all processes. Each A is an integer chosen randomly from a uniform distribution between 0 and some value k, where k is a simulation parameter. Each T is an integer chosen randomly from a uniform distribution between min_time and max_time, where min_time and max_time are simulation parameters Each R is initialized to T, since prior to execution, the remaining time is equal to the total CPU time required. Print each row of the table after it has been initialized.

Part 3:

Simulation Algorithms

Implement the scheduling algorithms for FCFS, SJF, and SRT. Each algorithm should take the simulation table as a parameter as well as the currently running process id (use -1 to indicate no process is currently running) and the current time step. It should return the process id of the process to run during this time step (this may or may not be the same as the currently running process id that was passed in as a parameter).

Part 4:

Simulator

Implement the simulator using the psuedo-code shown here:

for each scheduling algorithm:

repeat until R == 0 for all n processes /* repeat until all processes have terminated */

activate any process whose arrival time = t

while no process is active, increment t /* if no process is ready to run, just advance t */

choose active processes p to run next

according to scheduling algorithm /* Ex: FIFO, SJF, SRT */

print the timestep and p

decrement R /* p has accumulated 1 CPU time unit */

if R == 0 /* process i has terminated */

set active flag of p = 0 /* process i is excluded from further consideration */

TT = (t+1) - A /* the turnaround time of process i is the time since arrival, TT, until the current time t + 1 */

increment t /* move to the next time step */

compute the average turnaround time, ATT, by averaging all values TT print the scheduling alorithm and the ATT reset Ri == Ti for all n process /* Reset the remaining time for each process so the table can be re-used for the next algorithm */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

What are the elements of comprehensive auditing?

Answered: 1 week ago

Question

Solve the equation. x 2 + 3x - 2 = 0

Answered: 1 week ago

Question

What would you do?

Answered: 1 week ago