0% found this document useful (0 votes)
8 views5 pages

Operating System Lecture 8

The document discusses scheduling algorithms, specifically First-Come First-Served (FCFS) and Shortest Job First (SJF). It outlines the properties, advantages, and disadvantages of FCFS, including examples with calculations for Turnaround Time (T.A.T) and Waiting Time (W.T). Additionally, it explains SJF, emphasizing its non-preemptive nature and providing examples for calculating average T.A.T and W.T.

Uploaded by

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

Operating System Lecture 8

The document discusses scheduling algorithms, specifically First-Come First-Served (FCFS) and Shortest Job First (SJF). It outlines the properties, advantages, and disadvantages of FCFS, including examples with calculations for Turnaround Time (T.A.T) and Waiting Time (W.T). Additionally, it explains SJF, emphasizing its non-preemptive nature and providing examples for calculating average T.A.T and W.T.

Uploaded by

saifgoran037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Scheduling Algorithms:-

1- First-come First served scheduling (FCFS):-


Process that requests the CPU first is allocated the CPU first. The
implementation of the FCFS policy is easily managed with a FIFO queue.

The disadvantage of FCFS is: -


1- Waiting time is long.

2- Throughput is small.

3- Utilization of resource is small.

What are the properties of the FCFS scheduling Algorithm?

1- Is a non-preemptive scheduling.

2- Process keeps the CPU until it releases the CPU, either by terminating or by
requesting I/O.

3- The code is simple to write and understand.

Example 1:

Suppose you have the following processes that arrive at time zero (0) in order given,
with the length of the CPU-burst time given in millisecond.

Burst time Process

10 P1

1 P2

2 P3

1 P4

5 P5

Calculate the average of: 1- T.A.T 2- W.T using FCFS Algorithm?

1
Solution: Gantt chart

P1 P2 P3 P4 P5
0 10 11 13 14 19

T.A.T= Terminate time – Arrival time W.T= T.A.T – Burst time


T.A.T for P1 = 10 – 0 =10 W.T for P1 = 10 – 10 =0
P2 = 11 - 0 = 11 P2 = 11 - 1 = 10
P3 = 13 – 0 = 13 P3 = 13 – 2 = 11
P4 = 14 – 0 = 14 P4 = 14 – 1 = 13
P5 = 19 – 0 = 19 P5 = 19 – 5 = 14

Average of T.A.T = Average of W.T =


(10+11+13+14+19)/5= 67/5= 13.4 (0+10+11+13+14)/5= 48/5= 9.6

Example 2:-

Consider the following set of processes that arrive at time 0, with the length of the
CPU-burst time given in milliseconds:

Burst time Process

24 P1

3 P2

3 P3

Calculate the average of 1- T.A.T 2- W.T by using FCFS scheduling algorithm?

Solution:-

P1 P2 P3
0 24 27 30

T.A.T= Terminate time – Arrival time W.T= T.A.T – Burst time


T.A.T for P1 = 24 – 0 =24 W.T for P1 = 24 - 24 =0
P2 = 27 - 0 = 27 P2 = 27 – 3 = 24
P3 = 30 – 0 = 30 P3 = 30 – 3 = 27

Average of T.A.T = Average of W.T =


(24+27+30)/3= 81/5= 27 (0+24+27)/3= 51/3= 17

2
Note:-

If the processes arrive in order P2, P3, P1, however, the results will be as shown in
the following Gantt chart:

P2 P3 P1
0 3 6 30

T.A.T= Terminate time – Arrival time W.T= T.A.T – Burst time

T.A.T for P1 = 30 – 0 = 30 W.T for P1 = 30 - 24 = 6


P2 = 3 - 0 = 3 P2 = 3 – 3 = 0
P3 = 6 – 0 = 6 P3 = 6 – 3 = 3

Average of T.A.T = (30+3+6)/3= 39/3= 13 Average of W.T = (6+0+3)/3= 9/3= 3

:‫ ) وهي أن‬disadvantage (‫نستنتج من المثال أعاله أن لهذه الخوارزمية عيوب‬

‫) قصير ينتظر لفترة طويلة للحصول على‬CPU burst time( ‫ الذي فترة تنفيذه أو‬process ‫إن الـ‬
‫ هذا واضح من‬.‫) طويل‬CPU burst time) ‫ له‬process ‫) أذا كان وصوله إلى النظام خلف‬CPU( ‫المعالج‬
:‫) وهذه الخاصية تسمى ب‬P2,P3,P1( ‫) وعندما كان التسلسل‬P1,P2,P3( ‫المثال أعاله عندما كان التسلسل‬
Convoy effect
Convoy effect:- Short process being behind long or big process. Or all the other processes
wait for the one big process to get off the CPU. This effect results in lower CPU and device
utilization.

Example 3: (Homework)

Consider the following set of processes that arrive at different times, with the length of the
execution time given in milliseconds:

Process Arrival time execution time

P1 0 10

P2 0 1

P3 2 2

P4 3 1

P5 5 5

Calculate the average of: 1- T.A.T 2- W.T by using FCFS scheduling scheme?

3
2- Short Job First Scheduling Algorithm (SJFS):-
When the CPU is available, it is assigned to the process that has the smallest
next CPU burst time. Also called Shortest Next CPU Burst. If two processes
have the same length next CPU burst, FCFS scheduling is used to break the
time. The SJF algorithm be non-preemptive.

By moving a short process before a long one the waiting time of the short process
decreases more than it increases the waiting time of the long process, the average
waiting time decreases.

Example 1: Consider the following set of processes that arrive at different times,
with the length of the execution time given in milliseconds:

Process Arrival time Burst time

P1 0 7

P2 2 4

P3 4 1

P4 5 4

Calculate the average of: - 1- T.A.T 2- W.T by using SJF algorithm?

Solution:-

P1 P3 P2 P4
0 7 8 12 16

T.A.T= Terminate time – Arrival time W.T= T.A.T – Burst time

T.A.T for P1 = 7 – 0 =7 W.T for P1 = 7 – 7 =0


P2 = 12 - 2 = 10 P2 = 10 - 4 = 6
P3 = 8 – 4 = 4 P3 = 4 – 1 = 3
P4 = 16 – 5 = 11 P4 = 11 – 4 = 7

Average of T.A.T = Average of W.T =


(7+10+4+11)/4= 32/4= 8 (0+6+3+7)/4= 16/4= 4

4
Example 2: Consider the following set of processes that arrive at different times,
with the length of the execution time given in milliseconds:

Process Arrival time Burst time

P1 1 6

P2 1 3

P3 3 1

P4 3 4

Calculate the average of: - 1- T.A.T 2- W.T by using SJF algorithm?

CPU idle P2 P3 P4 P1
0 1 4 5 9 15

T.A.T= Terminate time – Arrival time W.T= T.A.T – Burst time


T.A.T for P1 = 15 – 1 =14 W.T for P1 = 14 – 6 = 8
P2 = 4 - 1 = 3 P2 = 3 - 3 = 0
P3 = 5 – 3 = 2 P3 = 2 – 1 = 1
P4 = 9 – 3 = 6 P4 = 6 – 4 = 2
Average of T.A.T = (14+3+2+6)/4=
25/4= 6.25 Average of W.T = (8+0+1+2)/4=
11/4= 2.75

Example: - Consider the following set of processes that arrive at different times,
with the length of the execution time given in milliseconds: (Homework)

Process Arrival time Burst time

P1 1 6

P2 1 3

P3 12 1

P4 12 4

Calculate the average of: - 1- T.A.T 2- W.T by using SJF algorithm?

You might also like