Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CPU scheduling is the basis of multiprogramming. Whenever a computer CPU becomes idle, the operating system must select a process in the ready queue to

CPU scheduling is the basis of multiprogramming. Whenever a computer CPU becomes idle, the operating system must select a process in the ready queue to be executed. One application of priority queues in operating systems is scheduling jobs on a CPU. In this project, you will write a program that schedules simulated CPU jobs on a single-core processor. Your program should run in a loop, each iteration of which corresponds to a time slice, one CPU cycle. Each job is assigned a priority, which is a random integer between -20 (highest priority) and 19 (lowest priority), inclusive. From among all jobs waiting to be processed in a time slice, the CPU must work on a job with the highest priority. When two jobs have the same priority the one created earliest will be processed. In this simulation each job comes with a length value, which is a random integer between 1 and 100, inclusive, indicating the number of time slices that are needed to complete this job. For simplicity, we will assume that the CPU is non-preemptive; that is, once a job is scheduled on the CPU, a job runs for a number of time slices equal to its length without being interrupted. Also, each process will have a process identification number 1 . . . n, where n is the number of simulated processes created.

Modes of Operations of the Simulator

The simulator runs in two modes: random, denoted by the command line argument -r or -R, or file, denoted by the command line argument -f or -F. In either mode, the simulator runs with three command line arguments. In either mode, the first command argument is a positive integer representing the number of CPU cycles for the simulation. In random mode the remaining command line arguments are the -r or -R flag followed a positive real number less than or equal to 1.0 representing the probability that a process is created during a CPU cycle. In file mode the remaining command line arguments are the -f or -F flag followed by the file name of the file containing information about the simulated jobs.

image text in transcribed

First, you will implement a priority queue ADT. Then you will use the ADT in writing a simple CPU scheduling simulator. At time zero the ready queue is empty. As described above, to run the simulator in random mode you will enter as a third command line argument p, a value between 0.01 and 1.00 inclusive. Your application will generate a random probability value q between 0 and 1 and for q p a simulated job will be created. You will then set the relevant instance fields of the simulated jobs with appropriate values. Each process control block also has additional fields to facilitate your analysis: A PCB has an arrived field, the time slice during which the process was created, start, the time slice when the process begins running, wait, the length of time from the process creation to when it begins running, and running, which is 0 if the process is waiting and 1 if the process is executing. Similarly, to run the simulator in file mode, you will enter a third command line argument representing the name of a text file containing information about the simulated jobs. Each line of this file will contain four integers. The first integer is the process identification number. The second number is an integer in [19, 20], the priority value of this process. The smaller this number, the higher the priority. The third number is an integer in [1, c], where c is the number of cycles that the simulator will run. The third number represents the cycle during which the process was created. The last number is a positive integer that represents the number of cycles required to execute the process. These values are used to set the relevant fields of the simulated jobs. In either mode, a simplifying assumption is that only one simulated job may be created during a cycle. Your application should trace these activities during each time slice:

1. *** Cycle #: c *** at the beginning of each cycle.

2. If the ready queue is empty, the message The CPU is idle should be displayed.

3. Whenever a process is finished executing, the message Process # pid has just terminated should be displayed.

4. If a process is still executing, the message Process # pid is executing. should be displayed.

5. Whenever a new process is created the message Adding job with pid # x and priority p and length t. should be displayed.

6. If no new process is created during a cycle, the message No new job this cycle. should be displayed.

At the end of the simulation, your program should also display the average throughput, number of processes completed per CPU cycle. It should also display the average wait time per process. The wait time of a process is the number of cycles from its creation to when it begins executing. To run your simulation for 1000 time slices (cycles) where the probability that a new process is created during each cycle is 0.2, your program will be executed with these values as command line tokens. Be sure to seed the random number generator using time of day. Do so at the beginning of the main. I have also provided a sample input file, simulatedjobs.txt and its corresponding output. When you run the simulator in file mode using this file, the simulator should display the output shown in simulatedjobsoutput.txt on the screen. See starter code that I have provided below for additional details. Modify the code only where indicated.

NOTE: Verify that your code has no syntax error and that it is ISO C++11 compliant prior to uploading it.

1.) (Heap.cpp) https://drive.google.com/file/d/1665vfuaqzRhQ28qjkgNj6QRqsx9EVHP7/view?usp=sharing

2.) (Heap.h) https://drive.google.com/file/d/1-4CUO1QdKg1fBfc2f8PJOXu10V6lPRwV/view?usp=sharing

3.) (PCB.h) https://drive.google.com/file/d/1e6MkT4PCUAWfSfkeS9SipACfpZIidW9J/view?usp=sharing

4.) (SingleCoreScheduler) https://drive.google.com/file/d/1dx4HFE53S-S5w0K7oPSadzvtSEf9-MSy/view?usp=sharing

Listing 1: Activities During a Cycle A. if (readyq is empty.) print idle CPU message if (readyQ head process is not running) endif else execute the head process if (readyQ head process is finished exeuting) terminate the process print process termination message else print process running message endif endif B. if (process is created) add the process to the readyQ print process created message else print no process created message endif Listing 1: Activities During a Cycle A. if (readyq is empty.) print idle CPU message if (readyQ head process is not running) endif else execute the head process if (readyQ head process is finished exeuting) terminate the process print process termination message else print process running message endif endif B. if (process is created) add the process to the readyQ print process created message else print no process created message endif

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago

Question

13. You always should try to make a good first impression.

Answered: 1 week ago