0% found this document useful (0 votes)
3 views

LSS Note

Process scheduling notes for lss

Uploaded by

ulrichzoda985
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)
3 views

LSS Note

Process scheduling notes for lss

Uploaded by

ulrichzoda985
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/ 8

Process scheduling

1. First Come First Serve Scheduling Algorithm (FCFS)


• FCFS is a simple scheduling algorithm
• In FCFS process are executed by the CPU according to the arrival time to the ready
queue
• In this scheduling algorithm the program that come fist will be executed first
• FCFS scheduling algorithm is a non-preemptive scheduling algorithm

Terminology use in CPU scheduling


• Arrival time: The time at which the process arrives the ready queues
• Completion time: The time at which the process completes it execution
• Turnaround time: The different between completion time and arrival time. (TAT =
CT- AT)
• Waiting time: Time different between Turnaround time and burst time. CPU Burst
time is the overall CPU time a process needs. (WT=TAT-BT)

Example
Consider the following process with burst time and arrival time given. Calculate the
waiting time and average waiting time in MS.
Process ID Burst time Arrival time
P1 24 0
P2 3 1
P3 4 2

Solution
▪ First draw your Gantt char
▪ When drawing the Gantt char Consider or follow the role of the algorithm
given to you, here is FCFS
▪ FCFS says that the first process that arrive the ready queue is the first to
execute by the CPU.
▪ Carefully look at the table given to you when drawing Gantt char
P1 P2 P3
0 24 27 31

Process ID Burst time Arrival time Completion Turnaround Waiting time


time time
P1 24 0 24 24 O
P2 3 1 27 26 23
P3 4 2 31 29 25

Average waiting time=O+23+25/3=16


Example 2
Consider the following set of process with burst time given. Calculate the waiting time and
the average waiting time in MS.

Process ID Burst time Order


P1 2 1
P2 10 2
P3 2 3
P4 6 4

P1 P2 P3 P4
0 2 12 14 20
waiting time
P1=0
P2=2
P3=12
P4=14
average waiting time=0+2+12+14=28/4=7

2. Short Job First (SJF)

• SJF algorithm associates each program with a processing time (Burst time), where the
program with the shorts processing time is executed first.
• When the CPU is available, it is assigned to the program with the shortest execution
time
• If the next CPU burst of two programs are the same, FCFS is use.
• The SJF can be both preemptive and non-preemptive.
• A more appropriate term for this scheduling method would be the “Short-next-CPU
burst because it depends on the length of the next CPU burs to the.

Example:
Consider the following set of processes with length of the CPU burst of each process
given in Ms. Calculate the waiting time and the average waiting time of these process.

Process ID Burst time


P1 6
P2 8
P3 7
P4 3

Solution
0 3 9 16 24

P4 P1 P3 P2

Watling time for P1=3ms


Waiting time for P2=16ms
Waiting time for P3=9ms
Waiting time for P4=0ms

Average waiting time = 3+16+9+0/4 = 7ms

Example 2 (preemptive)
Consider the following 4 processes with length of CPU burst time given in MS and the
process arrive at the ready queues at the time shown below. Calculate the waiting time
and the average waiting time.

Process ID Arrival time Burst time


P1 0 8
P2 1 4
P3 2 9
P4 3 5

P1 P2 P4 P1 P3
0 1 5 10 17 26
Waiting time= Turnaround time – burst time
Turnaround time = Completion time – Arrival time
Process ID Arrival time Burst time Completion Turnaround Waiting time
time time
P1 0 8 17 17 9
P2 1 4 5 4 0
P3 2 9 26 24 15
P4 3 5 10 7 2

Average waiting time 9+0+15+2/4=6.5


problems

• The real difficulty with the SJF scheduling algorithm is to know the length of the next
process
• Although the SJF algorithm is optimal, it cannot be implemented at the level of short
term scheduling.
• There is no way to know the length of the next CPU scheduling
Solution

• Is to approximate SJF scheduling


• We may not now the length of the next CPU burst but we can predict its value
• We expect that the next CPU burst will be similar in length to the previous ones.
• Thus, by an approximation of the length of the next CPU burst we can pick the
process with the shortest predicted CPU burst.
Exercise
An operating system uses the shortest remaining time first scheduling algorithm for
preemptive scheduling of processes. Consider the following set of processes with their
arrival time and CPU bust given in Ms. Calculate the waiting time and the average waiting
time.

Process ID Arrival time Burst time


P1 0 12
P2 2 4
P3 3 6
P4 8 5

3. Priority scheduling algorithm


• Priority scheduling algorithm associate each process with a priority and the CPU is
allocated to the process with the highest priority
• Equal priority is solved with the FCFS scheduling algorithm
• It can be both preemptive and non-preemptive
• The lower the value the higher the priority
Examples
Consider the following set of process which is consider having the same arrival time
in the order P1, P2, P3, P4, P5 with the length of the CPU burst given in MS. calculate
Waiting time and the average waiting time

Process ID Burs time Priority


P1 1O 3
P2 1 1
P3 2 4
P4 1 5
P5 3 2

P2 P5 P1 P3 P4
0 1 4 14 16 17
Waiting time
P1=4
P2=0
P3=14
P4=16
P5=1
Average waiting time=0+1+4+14+16/5=7
Problems

• A major problem of priority scheduling is indefinite blocking or starvation


• A situation when a process that is ready but wait for the CPU is known as starvation
• A priority scheduling allows some low priority process to wait indefinitely
• In loaded computer system a steady stream of high priority process con prevents low
priority process from getting aces to the CPU.
Solution

• A solution to the problem of starvation is aging


• Aging is the process of gradually increasing the priority of process which are
waiting in the system for a long time.
Example 2
Consider the set of processes with arrival time and CPU burst time in MS and priority (O
is the highest priority) shown below, none of the processes has I/O burst time. Calculate
the waiting time and the average waiting time.
Process ID Arrival Time Burst Time Priority
P1 0 11 2
P2 5 28 0
P3 12 2 3
P4 2 10 1
P5 9 15 4

P1 P4 P2 P4 P1 P3 P5
0 2 5 33 40 49 51 66

Process Arrival Burst Priority Completion Turnaround Waiting


ID time tome time time time
P1 0 11 2 49 49 38
P2 5 28 0 33 28 0
P3 12 2 3 51 49 47
P4 2 10 1 40 38 28
P5 9 15 4 66 57 42

Average waiting timed= 38+0+47+28+42/5=31

4. Round robin scheduling algorithm


• RR scheduling algorithm is designed especially for time sharing system
• It is like FCFS scheduling but preemptive is added to switch between process.
• A small unit of time is defined which is called the time Quantum or time slice
(generally from 10 MS to 100 MS)
• Here the ready queue (where ready process is store before been process) is
threated as a circular queue.
• The OS go around the ready queue to allocate the CPU to each process for a time
interval of up to one-time quantum

Process ID

CPU Schedule
Diagram to illustrate RR schedule queue
Implementation of RR scheduling algorithm

Tail Head
FIFO

• We keep the ready queue as a FIFO (First in First Out) queue of processes
• New process is added to the tail of the queue
• The CPU scheduler pick up the first process from the ready queue, set a timer to
interrupt after 1 quantum, and dispatch the process.
Two things can happen after this stage

• The process may have a CPU burst less than onetime quantum
• The CPU it self will release the process voluntarily
• The CPU moves to the next process

OR
• The process will have a CPU burst more than onetime quantum
• A context switch will be executed, and the process will be place at the tail of the
ready queue
• The CPU moves to the next process

Problems

• Long burst time and time quantum

Example
Consider the following process that arrive at time 0, with the length of the CPU burst
time is given in MS and time is quantum taken as 4 MS for RR schedule. Calculate the
waiting time and the average waiting time.

Process ID Burst Time


P1 24
P2 3
P3 3
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Turnaround time = Completion time – Arrival time


Waiting time = Turnaround time – Burst time

Process ID Burst time Arrival time Completion Turnaround Waiting


Arrival time time time time
P1 24 0 30 30 6
P2 3 0 7 7 4
P3 3 0 10 10 7

Average waiting time = 6+4+7/3=5.6


Exercise
Consider the set of process whose arrival time and burst time are given bellow using
RR and quantum = 2 unit. Calculate the waiting and the average waiting time of these
process.

Process ID Arrival time Burst time


P1 0 5
P2 1 5
P3 2 1
P4 3 2
P5 4 5

You might also like