OS - Assignment 2
OS - Assignment 2
Roll. No: 28
B. Tech C.S.E
3rd Year Section> A
Assignment No.2
CPU Scheduling
Que.1
P1 2 7 0
P2 1 10 4
P3 0 15 3
P4 4 11 2
P5 3 4 1
What is the average waiting time and average turnaround time for these
processes
i) FCFS
ii) SJF
Sol.s 1
What is the average waiting time and average turnaround time for these processes
FCFS (First Come First Served)
FCFS schedules processes based on their arrival time. The process that arrives first is
executed first.
Execution Order:
Completion Times:
Turnaround Times:
Waiting Times:
0+14+22+27+32 /5=19
15+24+26+34+43/5=28.4
SJF schedules processes based on the shortest burst time first. Among the processes
that are ready, the one with the shortest burst time is executed next.
Execution Order:
Completion Times:
> P3: 15
Turnaround Times:
Completion Times:
> P5: 14
> P1: 28
> P2: 32
> P3: 38
> P4: 50
Turnaround Times:
Waiting Times:
Priority Scheduling
Execution Order:
> P1 (Priority = 0)
> P5 (Priority = 1)
> P4 (Priority = 2)
> P3 (Priority = 3)
> P2 (Priority = 4)
Completion Times:
> P1: 7 + 2 = 9
> P5: 13 (9 + 4)
Turnaround Times:
Que. 2
P1 0 6 3
P2 1 4 1
P3 2 5 2
P4 3 8 4
What is the average waiting time and average turnaround time for these
processes with following algorithms?
i) FCFS
ii) SJF
Sol.2
FCFS (First Come first Served)
Execution Order:
Completion Times:
> P1: 6 (0 + 6)
> P2: 10 (6 + 4)
Turnaround Times:
Waiting Times:
Execution Order:
1. Calculate availability:
> P1 (6 ms)
> P2 (4 ms)
> P3 (5 ms)
> P4 (8 ms)
Completion Times:
> P2: 5 (1 + 4)
> P3: 10 (5 + 5)
Turnaround Times:
Waiting Times:
Execution Order:
Completion Times:
> P4: 3 (1st Cycle) + 3 (2nd Cycle) + 3 (3rd Cycle) + 2 (4th Cycle) = 11 + 9 = 20
Turnaround Times:
Waiting Times:
Execution Order:
1. Sort by priority:
> P2 (Priority = 1)
> P3 (Priority = 2)
> P1 (Priority = 3)
> P4 (Priority = 4)
2. Order of execution:
Completion Times:
> P2: 5 (1 + 4)
> P3: 10 (5 + 5)
Turnaround Times:
Waiting Times:
Que.3
P1 2 5 3
P2 1 3 1
P3 0 8 2
P4 3 6 4
What is the average waiting time and average turnaround time for these
processes with following algorithms?
i) FCFS
ii) SJF
Sol.3
FCFS (First Come First Served)
Execution Order:
Completion Times:
> P3: 8 (0 + 8)
> P2: 11 (8 + 3)
Turnaround Times:
Waiting Times:
1. Calculate availability:
> P2 (3 ms)
> P1 (5 ms)
> P4 (6 ms)
> P3 (8 ms)
3. Order of execution:
> P2 (Arrival Time = 1, Burst Time = 3)
Completion Times:
> P2: 4 (1 + 3)
> P1: 9 (4 + 5)
> P4: 15 (9 + 6)
Turnaround Times:
Waiting Times:
Execution Order:
Completion Times:
Turnaround Times:
Waiting Times:
Priority Scheduling
Execution Order:
1. Sort by priority:
> P2 (Priority = 1)
> P3 (Priority = 2)
> P1 (Priority = 3)
> P4 (Priority = 4)
2. Order of execution:
Completion Times:
> P2: 4 (1 + 3)
> P3: 12 (4 + 8)
Turnaround Times:
Waiting Times: