You are on page 1of 7

Programme Name: BCS

Course Code: CSC 1016

Course Name: Operating System

Assignment: Second Assignment

Date of Submission: 10 August 2022

Submitted By: Submitted To:

Student Name: Achyut Neupane Faculty Name: Khushal Regmi

IUKL ID: 042103900002 Department: PO

Semester: 2nd Semester

Intake: September 2021


Q. 1. Assume that 5 processors enter ready state in a sequence as below:
Process Arrival time Burst time
P1 0 19
P2 3 3
P3 4 1

I. Draw Gantt chart if the processor schedulers use the following scheduling
algorithms
a. FCFS
b. SJF (Pre-emptive).
c. Round Robin with Quantum equal to 4 milliseconds
II. Compare the turnaround time for all the algorithms above.
III. Based on your results of the average turnaround time in b., which algorithm
is the best? Justify your answer
A
Abbreviations List

Abbreviations Definition
AT Arrival Time
BT Burst Time
CT Completion Time
TAT Turn Around Time
WT Waiting Time

a) Given the process above, using the following algorithm:


i FCFS
From the given processes, we can have this table:

Process AT BT CT TAT = CT-AT WT = TAT-BT


P1 0 19 19 19 0
P2 3 3 22 19 16
P3 4 1 23 19 18

The Gantt Chart using FCFS algorithm is:


ii SJF (Pre-emptive)
From the given processes, we can have this table:

Process AT BT CT TAT = CT-AT WT = TAT-BT


P1 0 19 23 23 4
P2 3 3 7 4 1
P3 4 1 5 1 0

The Gantt Chart using SJF (preemptive) algorithm is:

iii Round Robin


From the given processes and quantum time T=4ms, we can have this table:

Process AT BT CT TAT = CT-AT WT = TAT-BT


P1 0 19 23 23 4
P2 3 3 7 4 1
P3 4 1 8 4 4

The ready queue for these processes is:


𝑃1, 𝑃2, 𝑃3, 𝑃1

The Gantt Chart using Round Robin algorithm is:


b) The comparison between the average Turn Around Time (TAT) for all three
algorithms are:
i FCFS
19+19+19
→ 3
57
→ 3
→ 19 ms

ii SJF
23+4+1
→ 3
28
→ 3
→ 9.33 ms

iii Round Robin


23+4+4

3
31
→ 3
→ 10.33 ms

c) The average Turn-Around-Time for FCFS, SJF (Pre-emptive) and Round Robin
are 19ms, 9.33ms, and 10.33ms respectively. Comparing all, the average
turnaround time of SJF (Pre-emptive) is the lowest. So, this algorithm is best for
this process schedule.
Q. 2. Memory Management is the process of controlling and coordinating computer
memory and assigning portions. Here is given five memory partitions of 100K,
500K, 200K, 300K (in order).
How would the first-fit, best-fit, and worst-fit algorithms place processes of 190K,
288K, 112K, and 250K (in order)?
A The first-fit algorithm for memory management will assign the partitions in given way:

The best-fit algorithm for memory management will assign the partitions in given way:

The worst-fit algorithm for memory management will assign the partitions in given way:
Q. 3. Considering a system with five processes A through E and three resources of type X,
Y, Z. Resource type X has 10 instances, Y has 5 instances and type Z has 7 instances.
Suppose at time t0 following snapshot of the system has been taken:

Allocated Max Available


X Y Z X Y Z X Y Z
P 0 1 1 6 4 3 3 2 2
Q 2 0 0 3 1 2
R 2 1 1 7 1 2
S 3 1 1 4 2 2
T 0 0 2 4 3 3

Answer the following questions using the banker’s algorithm:


a. What is the content of the matrix Need?
b. Is the system in a safe state? If yes, then what is the safe sequence?

A Given,
The allocations are: X=10, Y=5, and Z=7
Available = 3, 2, 2

a. Need matrix:
We know,
Need[i, j] = Max[i, j] – Allocation[i, j]

Need
X Y Z
P 6 3 2
Q 1 1 2
R 5 0 1
S 1 1 1
T 4 3 1

b. Safety analysis:

Work = Available = 3,2,2


Finish[P, Q, R, S, T] = [false, false, false, false, false]

For P:
Need = 6, 3, 2
We know in P, Need > Work
So, finish flag remains false
i.e., Finish[P] = false

For Q:
Need = 1, 1, 2
We know in Q, Need  Work
So, finish flag is set to true
i.e., Finish[Q] = true
Also,
Work = Work + Allocation[Q]
= 3, 2, 2 + 2, 0, 0
= 5, 2, 2

For R:
Need = 5, 0, 1
We know in R, Need  Work
So, finish flag is set to true
i.e., Finish[R] = true
Also,
Work = Work + Allocation[R]
= 5, 2, 2 + 2, 1, 1
= 7, 3, 3

For S:
Need = 1, 1, 1
We know in S, Need  Work
So, finish flag is set to true
i.e., Finish[S] = true
Also,
Work = Work + Allocation[S]
= 7, 3, 3 + 3, 1, 1
= 10, 4, 4

For T:
Need = 4, 3, 1
We know in T, Need  Work
So, finish flag is set to true
i.e., Finish[T] = true
Also,
Work = Work + Allocation[T]
= 10, 4, 4 + 0, 0, 2
= 10, 4, 6
For P:
Need = 6, 3, 2
We know in P, Need  Work
So, finish flag is set to true
i.e., Finish[P] = true
Also,
Work = Work + Allocation[P]
= 10, 4, 6 + 0, 1, 1
= 10, 5, 7

Since, Finish is true for all processes and total Allocation matrix is equal to Work
matrix, the system is said to be in safe state.
The safe sequence is: Q, R, S, T, P

You might also like