Lecture6.1 SJF OS
Lecture6.1 SJF OS
2
Various Times related to the Process
1. Arrival Time
The time at which the process enters into the ready queue is called the arrival time.
2. Burst Time
The total amount of time required by the CPU to execute the whole process is called the
Burst Time. This does not include the waiting time. It is confusing to calculate the
execution time for a process even before executing it hence the scheduling problems based
on the burst time cannot be implemented in reality!
3. Completion Time
The time at which the process enters the completion state or the time at which the process
completes its execution, is called completion time.
3
Various Times related to the Process
4. Turnaround time
The total amount of time spent by the process from its arrival to its completion, is called
Turnaround time.
5. Waiting Time
The total amount of time for which the process waits for the CPU to be assigned is called
waiting time.
6. Response Time
The difference between the arrival time and the time at which the process first gets the
CPU is called Response Time.
4
Shortest Job First(SJF): Key Points
• The job with smallest Burst Time is executed first.
• This algorithm is helpful for those types of processing of jobs in which the
completion time of a job can be calculated easily like Batch-type processing.
• This algorithm can improve the CPU processing as it executes the shorter jobs first
which leads to a short turnaround time.
• SJF can be
• Non-preemptive (Simply SJF)
• Preemptive (SRTF)
SJF (Shortest Job First): Non - preemptive
Waiting time
P2 0
P1 3
P2 P1 P3 P3 7
0 3 7 12 AWT = 0+3+7/3
10/3= 3.33
Example 2
0 P4
0
Example 2
1 P3
P4
0
Example 2
2 P3 P1
P4
0
Example 2
3 P3 P1
P4
0 3
Example 2
P4
0 3
Example 2
4 P3 P5
P4 P1
0 3
Example 2
5 P3 P5 P2
P4 P1
0 3
Example 2
6 P3 P5 P2
P4 P1
0 3
Example 2
7 P3 P5 P2
P4 P1
0 3
Example 2
8 P3 P5 P2
P4 P1
0 3
Example 2
9 P3 P5 P2
P4 P1
0 3 9
Example 2
P4 P1
0 3 9
Example 2
10 P3 P5
P4 P1 P2
0 3 9
Example 2
11 P3 P5
P4 P1 P2
0 3 9 11
Example 2
P4 P1 P2
0 3 9 11
Example 2
12 P3
P4 P1 P2 P5
0 3 9 11
Example 2
13 P3
P4 P1 P2 P5
0 3 9 11
Example 2
14 P3
P4 P1 P2 P5
0 3 9 11
Example 2
15 P3
P4 P1 P2 P5
0 3 9 11 15
Example 2
15 P3
P4 P1 P2 P5
0 3 9 11 15
Example 2
23
P4 P1 P2 P5 P3
0 3 9 11 15 23
Example 2
Process Burst time Arrival time
P1 6 2
P2 2 5
P3 8 1
P4 3
0
P5 4
4
P4 P1 P2 P5 P3
0 3 9 11 15 23
Waiting time = Start time – Arrival time
P4 = 0 - 0 = 0
P1 = 3 - 2 = 1
P2 = 9 - 5 = 4 Av. Waiting Time = 0+1+4+7+14/5 = 5.2
P5 = 11 - 4 = 7
P3 = 15 - 1 = 14
Try This: SJF(Non-preemptive)