Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective In this assignment, you will be writing a program that reads a list of process start times and durations from stdin. That list will

Objective

In this assignment, you will be writing a program that reads a list of process start times and durations from stdin. That list will be used four times to run through the following CPU scheduling algorithms: First Come, First Served Shortest Job First Shortest Remaining Time First Round Robin

Your program will show three statistics: the average process response time, the average process wait time, and the average process turnaround time for each scheduling algorithm. The time quantum for the Round Robin scheduler is 100ms. Your program only needs to work with a maximum of 25 processes.

Output

With this process list, the output of your program should look like this:

$ ./p5 < process-list.txt

First Come, First Served

Avg. Resp.: 276.40, Avg. T.A.: 448.90, Avg. Wait: 276.40

Shortest Job First Avg.

Resp.: 202.90, Avg. T.A.: 375.40, Avg. Wait: 202.90

Shortest Remaining Time First Avg.

Resp.: 148.30, Avg. T.A.: 353.30, Avg. Wait: 180.80

Round Robin with Time Quantum of 100

Avg. Resp.: 133.90, Avg. T.A.: 555.90, Avg. Wait: 383.40

Here's a smaller example of an input file. When you turn your program in it should use a time quantum of 100, but for this example you'll want to make it shorter. The Round Robin stats in the output are for a time quantum of 5.

5 8

8 10

15 3

17 2

Here's the output:

$ ./p5 < ex1.txt

First Come, First Served

Avg. Resp.:5.50, Avg. T.A.:11.25, Avg. Wait:5.50

Shortest Job First

Avg. Resp.:5.25, Avg. T.A.:11.00, Avg. Wait:5.25

Shortest Remaining Time First Avg.

Resp.:1.50, Avg. T.A.:8.50, Avg. Wait:2.75

Round Robin with Time Quantum of 5

Avg. Resp.:3.50, Avg. T.A.:12.00, Avg. Wait:6.25

Notes

Make four functions, one for each scheduling mechanism. Pass the input data to each function as a parameter. Do not modify your original arrays as you will be reusing the data in those arrays multiple times.

This program is simply an adder of process run times to a clock. Use the value of the clock to determine if new processes need to be added to your queue. Some students have tried to write a program that increments the clock one tick at a time. This is the difficult way to do it and is also incorrect.

Think about how to make good use of structs (structures) and functions. Even though C doesn't have classes and objects you can still use some of the same design concepts. Keep in mind that it's possible to pass a struct to a function by value, but if the function needs to change an element of the struct it will need a pointer to the struct.

The context switch cost is negligible and is not figured into this assignment.

Response time can be calculated by subtracting the process's arrival time from the clock time when the process first starts running. The waiting time is the total of all of the time intervals when the process is not running, after its arrival time and before it finishes. Turnaround time is calculated by subtracting the process's arrival time from the clock time when it finishes.

For round robin, new processes should be added to the ready queue before the process whose quantum just ended. For example, if P2 arrives at time 16 and P1's quantum ends at time 16, then P2 should be ahead of P1 in the ready queue.

You can assume that the process arrival times will be in order from smallest to largest in the input.

To avoid having to type in a lot of numbers every time you run the program you can use input redirection. Use a command like this: $ ./p5 < numbers.txt where numbers.txt is a plain-text file that has numbers separated by white space (spaces, newlines, or tabs).

You can use the fscanf function to read in numbers, like this:

int num; while (fscanf(stdin, "%d", &num) == 1) { // Copy the number from num to an array ... }

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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

=+Discuss the key benefits and challenges of a personal brand

Answered: 1 week ago

Question

1 . Television News channels importantance of our Life pattern ?

Answered: 1 week ago

Question

LO6 Describe how individual pay rates are set.

Answered: 1 week ago