Question

In: Computer Science

You are given the following processes with CPU-burst time, arrival time and priority (lower # means...

You are given the following processes with CPU-burst time, arrival time and priority (lower # means higher priority)

Process

CPU-burst

Arrival time

Priority

P1

12

0

5

P2

6

6

2

P3

9

1

2

P4

14

3

1

P5

7

5

4

For each of the following scheduling algorithm, show (using the diagram as in the slides), how the process are being executed. Also calculate the average wait time.

  1. Shortest job first (non-preemptive)
  2. Shortest remaining job first (preemptive)
  3. Priority-based (preemptive, with round robin on process with same priority, quantum = 3).
  4. Priority-based (preemptive, with round robin on process with same priority, quantum = 5).

A couple of other details:

  • If you need to preempt a job, only preempt when the new job has a strictly better criteria (priority, wait time etc.) Do not preempt if the criteria is the same.
  • For round robin, if a process is to be swap back to the end of the queue, and another process arrived at the same time, the newly arrived process should enter the queue first. Also, if multiple process that have the same priority can start, pick the one that arrive earlier first

You should present your output in the table below (the first two step of case (b) is done for you):

Time

Current Process Being Run

Order of the processes in the wait queue

0

P1

--

1

P3

{P1}

You should add an entry whenever a process is swapped out (or finished execution) and another process is swapped in.

Solutions

Expert Solution

Given Data:

Process

Burst-Time

Arrival Time

Priority

P1

12

0

5

P2

6

6

2

P3

9

1

2

P4

14

3

1

P5

7

5

4

  1. Shortest job first (non-preemptive)

We will solve using Gantt Chart

In the SJF algorithm, the process which has the smallest execution time (burst time) will be chosen for the next execution which is P2 and it will use the resource for 6 ms(12+6=18) completion time. The same process will be repeated.

P1

P2

P5

P3

P4

0 12 18 25 34 48

In the first step, we will select the process whose Arrival time is “0” which is P1 it will use the resource for till 12 and after P1 the process with the shortest burst time will be provided with the resource.

Waiting Time(Allocation Time - Arrival Time)

P1: 0 - 0 = 0 ms

P2: 12 - 6 = 6 ms

P3: 34 - 1 = 33 ms

P4: 48 - 3 = 45 ms

P5: 18 - 5 = 13 ms

Total Waiting Time = 97

Average Waiting Time: Total Waiting Time/ Number of processes

                                   : 97/5

                                   :19.4ms

OUTPUT: It is based on the burst time as well as arrival time the arrival time of P3 is 1 but it’s bust time is 9 and no other process has an arrival time 1 so only P1 will be there and the same will be followed by other processes.

Time

Current Process

Being Run Out

In Queue

0

P1

------

--------

1

P3

{P1}

{P1}

3

P4

{P1}

{P1,P3}

5

P5

{P1}

{P1}

6

P2

{P1}

{P1}

2. Shortest remaining job first (preemptive)

In this state the process switches from running state to ready state or waiting according to its arrival time and burst time.

P1

P3

P2

P5

P1

P4

0 1 10 16 23 34 48

Steps How the process allocation takes places:

P1 arrives at 0 when there was no process so it will take resource for 1 ms Burst TIme= 12-1

At 1 ms process, 3 will come 9-1=8 Still no process is there so it will take the resource 8-1=7 at 3 the P4 process will come but its time burst time is 14 so P3 will use the resource Till 10 because it will have lower burst time at 10 each process will arrive and this will become primitive scheduling.  

Waiting Time(Allocation Time - Arrival Time)

P1: 0 - 0 = 0 ms(It doesn’t matter if the process was removed.)

P2: 10 - 6 = 4 ms

P3: 1 - 1 = 0 ms

P4: 34 - 3 = 31 ms

P5: 16 - 5 = 11 ms

Total Waiting Time = 46

Average Waiting Time: Total Waiting Time/ Number of processes

                                   : 46/5

                                   :9.2ms

Priority-based (preemptive, with round-robin on the process with the same priority, quantum = 3).

The processes will run according to the priority.

According to the Arrival, Time P1 will arrive First and it will take 3 Quantum

Burst time Left 12-3=9

At Time 3 P3 will Arrive with burst time 9 and priority 2 and P4 also with burst time 14 and priority 1 so it will allocated to P4.P4=14-14=0 highest priority

At time 6 each process arrives.

P1

P4

P3

P2

P5

P1

0 3 17 26 32 39 48

Waiting Time(Allocation Time - Arrival Time)

P1: 0 - 0 = 0 ms(It doesn’t matter if the process was removed.)

P2: 26 - 6 = 20 ms

P3: 17 - 1 = 16 ms

P4: 3- 3 = 0 ms

P5: 32- 5 = 27 ms

Total Waiting Time = 36

Average Waiting Time: Total Waiting Time/ Number of processes

                                   : 63/5

                                   :12.6ms

Priority-based (preemptive, with round-robin on the process with the same priority, quantum = 5).

The processes will run according to the priority.

According to the Arrival, Time P1 will arrive First and it will take 3 Quantum

Burst time Left 12-5=9

At Time 5 P3, P4,P5 will Arrive .P4 priority is 1 so it will be allocated to P4.P4=14-14=0 highest priority


P1

P4

P3

P2

P5

P1

0 5 19 28 34 41 48

Waiting Time(Allocation Time - Arrival Time)

P1: 0 - 0 = 0 ms(It doesn’t matter if the process was removed.)

P2: 28 - 6 = 22 ms

P3: 19 - 1 = 18 ms

P4: 5- 3 = 2 ms

P5: 34- 5 = 31 ms

Total Waiting Time = 73

Average Waiting Time: Total Waiting Time/ Number of processes

                                   : 73/5

                                   :14.6ms


Related Solutions

1. Consider the following set of processes, with the length of CPU burst and arrival time...
1. Consider the following set of processes, with the length of CPU burst and arrival time given in milliseconds.                                                              Process            Burst time       Priority            Arrival Time             P1                         10                    3                              0 P2                          1                     1                              2 P3                          2                     4                              4 P4                          5                     2                              8 a) Draw the Gantt chart that illustrates the execution of these processes using the preemptive priority scheduling algorithm (a smaller priority number implies a higher priority). b) What...
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:...
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process          Burst Time     P1                             5         P2                             3             P3                             1           P4                             7            P5                             4            The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. If FCFS scheduling is used, what is the average turnaround time of these processes? Answer: Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process          Burst Time     P1                             5         P2                             3             P3                             1           P4                             7            P5                             4           ...
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:...
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process Arrival Time Burst Time P1 0 5 P2 2 3 P3 3 2 P4 4 4 P5 5 3 a. Draw Gantt charts illustrating the execution of these processes using SJF pre-emptive b. What is the turnaround time of each process for each of the scheduling algorithms c. What is the waiting time of each process for each of the scheduling algorithms  
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:...
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process Burst Time Priority Arrival Time P1 10 3 0 P2 1 1 12 P3 2 4 0 P4 1 5 0 P5 5 2 0 In the above table, a smaller priority number implies a higher priority. Suppose that these processes are scheduled by the priority policy with preemption. Draw the Gantt chart (i.e., time chart) illustrating the execution of these processes. What...
For Priority Scheduling, What is the arrival time, completion time, burst time, turnaround time, and the...
For Priority Scheduling, What is the arrival time, completion time, burst time, turnaround time, and the waiting time? discuss these terms further as they pertain to the efficiency of the algorithm as well as properties such as starvation. Pros and Cons of Priority Scheduling
Consider the following set of processes, with the length of the CPU burst given in milliseconds:...
Consider the following set of processes, with the length of the CPU burst given in milliseconds: Process Burst Time Priority P1 2 2 P2 1 1 P3 8 4 P4 4 2 P5 5 3 The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, non preemptive priority (a smaller priority number implies...
6. Consider the following set of processes P1, P2, P3, P4. Process Burst Time Arrival Time...
6. Consider the following set of processes P1, P2, P3, P4. Process Burst Time Arrival Time Priority P1 3 0 1 P2 5 1 2 P3 8 3 3 P4 4 4 2 a) Draw Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: first-come, first-served (FCFS), priority scheduling (larger number=high priority), and Round-Bobin (RR, quantum=2). b) Compute the average waiting time, turnaround time for the three algorithms. Turnaround time – amount of time to...
A set of processes along with their burst time in milliseconds is given below. The processes...
A set of processes along with their burst time in milliseconds is given below. The processes should execute in First Come First Served order. Assume that the quantum (q) is 3: Process Burst Time P1 22 P2 4 P3 12 P4 15 P5 2 Find the average waiting time using the Round Robin algorithm. Round your answer to 2 decimal places
Consider the set of processes shown in the table above, with the length of the CPU-burst...
Consider the set of processes shown in the table above, with the length of the CPU-burst time given in milliseconds. The processes are assumed to have arrived in the order P5, P4, P3, P2 , and P1, all approximately at time 0. Draw three Gantt charts illustrating the execution of these processes using SJF, Round-Robin (quantum size = 3), and a non-preemptive priority (a smaller priority number implies a higher priority) scheduling. Calculate average waiting time of each scheduling. Calculate...
What is the arrival time, completion time, burst time, turnaround time, and the waiting time of...
What is the arrival time, completion time, burst time, turnaround time, and the waiting time of First Come First Serve (FCFS)?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT