0% found this document useful (0 votes)
39 views7 pages

Proble Solution Os

Uploaded by

KOMAL JADHAV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views7 pages

Proble Solution Os

Uploaded by

KOMAL JADHAV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1 ) Round Robbin

 P1: Arrival Time = 0, Burst Time = 8


 P2: Arrival Time = 1, Burst Time = 5
 P3: Arrival Time = 3, Burst Time = 3
 P4: Arrival Time = 4, Burst Time = 1
 P5: Arrival Time = 6, Burst Time = 4
 Time Quantum (RR): 2 units

Round Robin (RR) Scheduling with Time Quantum = 2

In Round Robin, each process is given a fixed time slice (quantum). If a process's burst time
exceeds the quantum, it is placed at the end of the ready queue and will resume after all other
processes have had their turn.

Let's determine the Gantt chart and calculate the waiting time and turnaround time for each
process.

Step-by-Step Execution:

1. Initial Setup: Processes arrive as follows:


o At time 0: P1 arrives.
o At time 1: P2 arrives.
o At time 3: P3 arrives.
o At time 4: P4 arrives.
o At time 6: P5 arrives.
2. Execution Order (with 2 units time quantum):
o P1 starts at time 0 and runs for 2 units (remaining 6 units).
o P2 starts at time 2 and runs for 2 units (remaining 3 units).
o P3 starts at time 4 and runs for 2 units (remaining 1 unit).
o P4 starts at time 6 and runs for 1 unit (completes).
o P1 resumes at time 7 and runs for 2 units (remaining 4 units).
o P2 resumes at time 9 and runs for 2 units (remaining 1 unit).
o P3 resumes at time 11 and runs for 1 unit (completes).
o P5 starts at time 12 and runs for 2 units (remaining 2 units).
o P1 resumes at time 14 and runs for 2 units (remaining 2 units).
o P2 finishes at time 16.
o P5 resumes at time 16 and runs for 2 units (remaining 0 units).
o P1 finishes at time 18.

Gantt Chart for Round Robin (RR)


| P1 | P2 | P3 | P4 | P1 | P2 | P3 | P5 | P1 | P2 | P5 | P1 |
0 2 4 6 7 9 11 12 14 16 18 21 23
Completion Times (CT):

 P1: 23 (finishes at time 23)


 P2: 16 (finishes at time 16)
 P3: 12 (finishes at time 12)
 P4: 5 (finishes at time 5)
 P5: 18 (finishes at time 18)

Calculations:

1. Waiting Time (WT):

 Waiting Time (WT) is calculated as:


WT=Completion Time−Arrival Time−Burst Time

For each process:

 P1: WT=23−0−8=
 P2: WT=16−1−5=10
 P3: WT=12−3−3=6
 P4: WT=5−4−1=0
 P5: WT=18−6−4=8

2. Turnaround Time (TAT):

 Turnaround Time (TAT) is calculated as:


TAT=Completion Time−Arrival Time
 For each process:

 P1: TAT=23−0=23
 P2: TAT=16−1=15
 P3: TAT=12−3=9
 P4: TAT=5−4=1
 P5: TAT=18−6=12

Average Waiting Time (AWT) and Average Turnaround Time (ATAT):

 Average Waiting Time (AWT):

AWT=15+10+6+0+8=39 = 7.8

5 5

Average Turnaround Time (ATAT):

ATAT=23+15+9+1+12/5=60/5=12
Summary Table:

Arrival Burst Completion Time Waiting Time Turnaround Time


Process
Time Time (CT) (WT) (TAT)
P1 0 8 23 15 23
P2 1 5 16 10 15
P3 3 3 12 6 9
P4 4 1 5 0 1
P5 6 4 18 8 12

Final Averages:

Average Waiting Time Average Turnaround Time


Scheduling Algorithm
(AWT) (ATAT)
Round Robin (RR) 7.8 12

This concludes the solution for the Round Robin (RR) scheduling algorithm with the given
processes.

2) Sortest Job First


Shortest Job First (SJF) Scheduling

In SJF, processes with the shortest burst time are executed first. If two processes have the
same burst time, the one with the earliest arrival time is executed first.

Step-by-Step Execution:

Arrival Times and Burst Times:

 P1: Arrival Time = 0, Burst Time = 8


 P2: Arrival Time = 1, Burst Time = 5
 P3: Arrival Time = 3, Burst Time = 3
 P4: Arrival Time = 4, Burst Time = 1
 P5: Arrival Time = 6, Burst Time = 4

Execution Order:

1. At time 0: Process P1 arrives, so it is the first to run.


2. At time 1: P2 arrives, but it has a longer burst time than P1, so P1 continues.
3. At time 3: P3 arrives, and it has the shortest burst time (3 units), so P3 runs.
4. At time 4: P4 arrives, and it has the shortest burst time (1 unit), so P4 runs.
5. After P4 completes, P3 will resume and complete.
6. P2 then runs, followed by P5, and finally P1 completes last.

Gantt Chart for SJF:


The Gantt chart illustrates the order of execution of the processes based on their burst times:

Copy code
| P1 | P2 | P3 | P4 | P3 | P5 | P1 |
0 8 13 16 17 21 23 27

Completion Times (CT):

 P1: 27
 P2: 13
 P3: 16
 P4: 5
 P5: 21

Waiting Time (WT):

Waiting time is calculated as:

WT=Completion Time−Arrival Time−Burst Time

For each process:

 P1: WT=27−0−8=19
 P2: WT=13−1−5=7
 P3: WT=16−3−3=10
 P4: WT=5−4−1=0
 P5: WT=21−6−4=11

Turnaround Time (TAT):

Turnaround time is calculated as:

TAT=Completion Time−Arrival Time

For each process:

 P1: TAT=27−0=27
 P2: TAT=13−1=12
 P3: TAT=16−3=13
 P4: TAT=5−4=1
 P5: TAT=21−6=15

Average Waiting Time (AWT) and Average Turnaround Time (ATAT):

 Average Waiting Time (AWT):

AWT=19+7+10+0+11/5=47/5=9.4

Average Turnaround Time (ATAT):


ATAT=27+12+13+1+15/5=68/5=13.6

Summary Table for SJF:

Arrival Burst Completion Time Waiting Time Turnaround Time


Process
Time Time (CT) (WT) (TAT)
P1 0 8 27 19 27
P2 1 5 13 7 12
P3 3 3 16 10 13
P4 4 1 5 0 1
P5 6 4 21 11 15

Final Averages:

Average Waiting Time Average Turnaround Time


Scheduling Algorithm
(AWT) (ATAT)
Shortest Job First 13.6
9.4
(SJF)

3) First-Come, First-Served (FCFS) Scheduling


In FCFS, processes are executed in the order of their arrival times. If multiple processes
arrive at the same time, they are executed in the order they are listed.

Step-by-Step Execution:

1. Arrival Times and Burst Times:


o P1: Arrival Time = 0, Burst Time = 8
o P2: Arrival Time = 1, Burst Time = 5
o P3: Arrival Time = 3, Burst Time = 3
o P4: Arrival Time = 4, Burst Time = 1
o P5: Arrival Time = 6, Burst Time = 4
2. Execution Order (Based on FCFS):
o P1 arrives first and runs from time 0 to 8.
o P2 arrives at time 1, but it has to wait until P1 finishes, so it runs from time 8
to 13.
o P3 arrives at time 3, but it has to wait until P2 finishes, so it runs from time 13
to 16.
o P4 arrives at time 4, but it has to wait until P3 finishes, so it runs from time 16
to 17.
o P5 arrives at time 6, but it has to wait until P4 finishes, so it runs from time 17
to 21.

Gantt Chart for FCFS:

The Gantt chart illustrates the order of execution of the processes based on their arrival times:
Copy code
| P1 | P2 | P3 | P4 | P5 |
0 8 13 16 17 21

Completion Times (CT):

 P1: 8 (finishes at time 8)


 P2: 13 (finishes at time 13)
 P3: 16 (finishes at time 16)
 P4: 17 (finishes at time 17)
 P5: 21 (finishes at time 21)

Waiting Time (WT):

Waiting time is calculated as:

WT=Completion Time−Arrival Time−Burst Time

For each process:

 P1: WT=8−0−8=0
 P2: WT=13−1−5=7
 P3: WT=16−3−3=10
 P4: WT=17−4−1=12
 P5: WT=21−6−4=11

Turnaround Time (TAT):

Turnaround time is calculated as:

TAT=Completion Time−Arrival Time

For each process:

 P1: TAT=8−0=8
 P2: TAT=13−1=12
 P3: TAT=16−3=13
 P4: TAT=17−4=13
 P5: TAT=21−6=15

Average Waiting Time (AWT) and Average Turnaround Time (ATAT):

 Average Waiting Time (AWT):

AWT=0+7+10+12+115=405=8

 sAverage Turnaround Time (ATAT):

ATAT=8+12+13+13+155=615=12.2
Summary Table for FCFS:

Arrival Burst Completion Time Waiting Time Turnaround Time


Process
Time Time (CT) (WT) (TAT)
P1 0 8 8 0 8
P2 1 5 13 7 12
P3 3 3 16 10 13
P4 4 1 17 12 13
P5 6 4 21 11 15

Final Averages:

Average Waiting Time Average Turnaround Time


Scheduling Algorithm
(AWT) (ATAT)
First-Come, First-Served
8 12.2
(FCFS)

This concludes the solution for the First-Come, First-Served (FCFS) scheduling algorithm
with the given processes.

You might also like