LSS Note
LSS Note
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
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
• 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.
Solution
0 3 9 16 24
P4 P1 P3 P2
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.
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
• 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
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
P1 P4 P2 P4 P1 P3 P5
0 2 5 33 40 49 51 66
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
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.