Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92536879
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Question suppose you are planning a party for 10 friends

Question : Suppose you are planning a party for 10 friends. You decide to make sandwiches to serve at the party, no more than one sandwich per person. Seven of your friends say they want turkey. Five say they want roast ...

Explain why some organizations may not place enough

Explain why some organizations may not place enough importance on disaster recovery. What might happen to these organizations in the event of an actual disaster?

Imagine an election with just two candidates candidate a

Imagine an election with just two candidates. Candidate A asks her consultant to conduct a poll to see if she (Candidate A) is leading. What is the "null hypothesis" value that is being "tested" in this example?  Your an ...

What decimal number does the bit pattern 0xc0d40000

What decimal number does the bit pattern 0xC0D40000 represent if it is: A two's complement integer An unsigned integer A floating point number assuming the IEE 754 single precision format Please provide a detailed explan ...

Objectivesthis assessment item relates to the unit learning

Objective(s) This assessment item relates to the unit learning outcomes as in the unit descriptors. This checks your understanding about basic constructs of C# programming. Details & Problems In this assignment, you are ...

Consider a project to supply 97 million postage stamps per

Consider a project to supply 97 million postage stamps per year to the U.S. Postal Service for the next five years. You have an idle parcel of land available that cost $1,690,000 five years ago; if the land were sold tod ...

Artificial intelligence techniques assignment -

Artificial Intelligence Techniques Assignment - Combinatorial Optimisation Learning Outcomes Covered 1. Research and analyse the general nature of artificial intelligence and the problems it solves. 2. Apply and evaluate ...

Suppose that the government is coming up with an employment

Suppose that the government is coming up with an employment protection policy that requires firms to pay each laid-off worker two more months of salary after they are laid off. This essentially changes the variable adjus ...

Case study 1 user interfacesearly user interfaces were

Case Study 1: User Interfaces Early user interfaces were designed with little or no consideration for the end user. This was largely due to technical and hardware limitations. The poor interface design required a specifi ...

When using todays digital cameras file sizes are often

When using today's digital cameras file sizes are often saved in a format that is well over 1 Megabyte. This may be great for high definition photo reproductions but is a disaster for uploading to the web. Images on your ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As