Priority scheduling with preemption

Assignment Help Business Management
Reference no: EM131729813

Write code (C or Java) to simulate the following CPU scheduling algorithms, assuming a single CPU.

1. Round Robin

Add the processes to a regular First-In-First-Out (FIFO) queue in the order they arrive. If multiple processes arrive at the same time, add them to the queue in the order they appear in the input file. When the time quantum expires, the process that has the CPU is placed at the end of the queue if it has not terminated yet. If a new process arrives and a time quantum expires at the same time, insert the new arrival at the end of the queue before inserting the process whose time quantum expired. After Time 0, scheduling decisions are made when either the process that has the CPU terminates or the time quantum expires. In either case, the scheduler gives the CPU to the first process in the queue. The value of the time quantum is a parameter that is specified in the input file next to the algorithm's name as shown in Example 1 below.

2. Shortest Job First (SJF)

Assume no-preemption but take arrival times into account. To do that, you have to simulate the time (by simply defining an integer variable that keeps track of the time). At any given point in time, your scheduler considers only the processes that have arrived. Whenever a new process arrives, add it to a priority queue in which the key is the CPU burst length. After Time 0, scheduling decisions are made only when the process that currently has the CPU terminates. The scheduler will then give the CPU to the process with the shortest CPU burst. Ties must be broken based on arrival times, that is, if the ready queue has two or more processes with the same CPU burst, these processes get the CPU in the order they have arrived (FCFS). If multiple processes have the same CPU burst and the same arrival time, ties are broken arbitrarily.

3. Priority Scheduling without Preemption (PR_noPREMP)

Take arrival times into account. Whenever a new process arrives, add it to a priority queue, in which the key is the priority value read from the input file. After Time 0, scheduling decisions are made only when the process that currently has the CPU terminates (no preemption). The scheduler will then give the CPU to the process with the highest priority (smallest priority number). Ties are broken arbitrarily.

4. Priority Scheduling with Preemption (PR_withPREMP)

Take arrival times into account, and implement preemption. Whenever a new process arrives, add it to a priority queue, in which the key is the priority number read from the input file. After Time 0, scheduling decisions are made when the process that currently has the CPU terminates or when a higher priority process arrives. The schedule will then give the CPU to the process with the highest priority (smallest priority number). Ties are broken arbitrarily. If the process with the highest priority is the new process that has just arrived, the process that has the CPU must get preempted and added to the priority queue (unless it has just terminated at that point).

Your program should read an input file named "input.txt" and write the results into an output file named "output.txt". The formats of these files are as follows:

Input File

The first line has the name of the scheduling algorithm to run (one of the four names given above). 

The second line has a single integer representing the number of processes in the file.

In the rest of the file, there is one line per process with the following information:

Process number          Arrival Time          CPU burst time           Priority

If multiple processes have the same arrival time, your scheduling algorithm should assume that the processes have arrived in the order they appear in the file (there are negligibly small differences in arrival times). For priority scheduling, assume that smaller numbers indicate higher priorities. Non-priority algorithms should simply ignore the priority field.

Output File

Your output file will show the scheduling results for each of the algorithms listed in the input file. The first line in the output file has the name of the scheduling algorithm. The file then shows the schedule using a simple text format in which there is one line for each CPU assignment (each line corresponds to a vertical line in the Gantt chart). Each line has two numbers: one indicating the time point and one indicating the process number that got the CPU at that point. The last line in the output file shows the average waiting time.

Examples

As shown in the example below, when the algorithm is RR, there should be an integer parameter next to the algorithm's name specifying the length of the time quantum:

Input 1 (from the book)

RR 4

3

1    0     24     1

2    0     3       1

3    0     3       1

Output 1

    RR  4

0          1

4    2

7    3

10  1

14  1

18  1

22  1

26  1

AVG Waiting Time: 5.67

Reference no: EM131729813

Questions Cloud

Develop a module on influence without authority : Develop three course objectives regarding influencing skills-one focused on knowledge or comprehension, one tapping into application or analysis
What kind of organizations uses it governance : What kind of organizations uses IT Governance? How do you implement and IT governance program? How do you choose which framework to use?
Analyze the unique tactics and techniques : Analyze the unique tactics, techniques, and capabilities within the historical context of your chosen international terrorist organization .
Discuss what should be the carrying amount of this leasehold : In Nobb's December 31, year 3 balance sheet, what should be the carrying amount of this leasehold improvement
Priority scheduling with preemption : Take arrival times into account, and implement preemption. Whenever a new process arrives, add it to a priority queue, in which the key is the priority number.
Discuss what amount should shear report as deferred : what amount should Shear report as deferred income tax expense
Discuss about the statistical software package : Removing water from paper. The percentage of water removed from paper as it passes through a dryer depends on the temperature of the dryer and the speed.
Explain what factor interaction means for thw experiment : Auditor risk study. Accounting Review (January 1991) reported on a study of the effect of two factors, confirmation of accounts receivable and verification.
Define what is the net effect of the required adjustment : what is the net effect of the required adjustment on accumulated other comprehensive income

Reviews

Write a Review

Business Management Questions & Answers

  How many rooms could be painted by both workers

a. How many rooms could be painted by both workers? b. If a decision were made to only sand floors, how many floors could be sanded?

  Explain a business negotiation situation related to industry

Use the Internet or other resources to find at least two articles that describe a business negotiation situation related to two different industry sectors within Fortune 500 companies that employs different negotiation strategies

  Consider ethnic factors in sales

Do you feel it is discriminatory to consider ethnic factors when assigning sales reps to territories? (For example, is it considered discrimination to ensure that an African American salesperson is assigned to a territory that services African Ame..

  Devise a plan to investigate the validity of patients

Devise a plan to investigate the validity of patients' claims of denial of services. This plan should include, but not be limited to, establishing mechanisms to address service denial claims, a human resources component, and a review of related po..

  How loss prevention is relevant to hfe

Please read the attached article and answer the following questions: What is loss prevention and what are its elements? Elaborate in less than 500 words. How loss prevention is relevant to HFE? Elaborate and give examples in less than 500 words.

  Common method of conducting global business

Direct foreign investment is an increasingly important and common method of conducting global business.

  Zero-coupon bond with a maturity value

In July, 2005, your bond had 10 years remaining until maturity. Rates on bonds of comparable length were around 5.2%. You decide to sell your bond to an investor looking for a return of 5.2% annually.

  What are the components of competitive strategy

What are the components of competitive strategy? Within competitive strategy what is the relevance of a value change framework?

  Organizational culture-communication processes and tactics

Explain what communication processes or tactics would you use to improve the culture and what measurement tools would you use to ensure that you succeeded?

  Integer as a parameter and returns the number

Write a Reverse Digit method or function that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of Reverse Digit (12345) is 54321. Also, write a program (main function) to test your method.

  Problem regarding the four season success

Do human resources strategies play a in Four Season's success? if so, how and why?

  Which of given is a legitimate subject matter for a patent

Which of following is a legitimate subject matter for a patent? Which of following is not a factor in determining whether a trademark is inherently distinctive?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd