SHORTEST JOB
FIRST(SJF)
PRESENTED BY
NAME:SHUBHAM GUPTA
UNIVERSITY ROLL:12000221054
BRANCH:INFORMATION
TECHNOLOGY
SUBJECT CODE:PCC-CS502
TOPIC OVERVIEW
CPU SCHEDULING
PREEMTIVE & NON PREEMPTIVE
CLASSIFICATION OF PREEMPTIVE & NON PREEMPTIVE
INTRODUCTION OF SHORTEST JOB FIRST(SJF)
ALGORITHM OF SJF
EXAMPLE OF SJF
ADVANTAGE AND DISADVANTAGE OF SJF
CPU SCHEDULING
CPU Scheduling is a process of determining which process will own
CPU for execution while another process is on hold. The main task of
CPU scheduling is to make sure that whenever the CPU remains idle,
the OS at least select one of the processes available in the ready
queue for execution. The selection process will be carried out by the
CPU scheduler. It selects one of the processes in memory that are
ready for execution.
TYPE OF CPU SCHEDULING
Non preemptive –Non-Preemptive scheduling is used when a
process terminates , or when a process switches from running state
to waiting state.
Preemptive –Preemptive scheduling is used when a process switches
from running state to ready state or from the waiting state to the
ready state. This scheme is known as the Shortest-Remaining-Time-
First (SRTF).
CLASSIFICATION OF PREEMTIVE
AND NON PREEMTIVE
CPU
SCHEDULING
PRE-EMTIVE
NON PRE-
EMTIVE
SRTM
LRTM
LJF
SJF
FCFS
ROUND ROBIN
INTRODUCTION OF SHORTEST JOB
FIRST(SJF)
The shortest job first (SJF) or shortest job next, is a scheduling
policy that selects the waiting process with the smallest
execution time to execute next.
SJN, also known as Shortest Job Next (SJN)
It can be preemptive or non-preemptive both.
Preemptive SJF is also called Shortest Remaining Time First.
ALGORITHM OF SJF
Sort all the processes according to the arrival time.
Then select that process that has minimum arrival time and minimum
Burst time.
After completion of the process make a pool of processes that arrives
afterward till the completion of the previous process and select that
process among the pool which is having minimum Burst time.
BEFORE GOING TO EXAMPLE YOU
MUST KNOW THIS TERM
Arrival Time: Time at which the process arrives in the ready queue.
Completion Time: Time at which process completes its execution.
Burst Time: Time required by a process for CPU execution.
Turn Around Time: Time Difference between completion time and
arrival time.
Turn Around Time = Completion Time – Arrival Time
Waiting Time(W.T): Time Difference between turn around time and
burst time.
Waiting Time = Turn Around Time – Burst Time
EXAMPLE OF NON PREEMPTIVE SJF
CONSIDER THE SET OF 5 PROCESSES WHOSE ARRIVAL TIME AND BURST TIME ARE GIVEN BELOW-
Process Id Arrival time Burst time
P1 3 1
P2 1 4
P3 4 2
P4 0 6
P5 2 3
GANNT
CHART
Process Id Arrival time Burst time
P1 3 1
P2 1 4
P3 4 2
P4 0 6
P5 2 3
P4 P1 P3 P5 P2
0 6 12
9
7 16
COMPLETION
TIME (CT)
Process Id Arrival Time
Burst
Time
Completio
n time
Turn around
Time(CT-AT)
Waiting
Time(TAT-
BT)
P1 3 1 7 7-3 = 4 4-1 = 3
P2 1 4 16 16-1 = 15 15-4 = 11
P3 4 2 9 9-4 = 5 5-2 = 3
P4 0 6 6 6-0 = 6 6-6 = 0
P5 2 3 12 12-2 = 10 10-3 = 7
GANNT
CHART
Average Turn Around time = (4 + 15 + 5 + 6 + 10) / 5 = 40
/ 5 = 8
Average waiting time = (3 + 11 + 3 + 0 + 7) / 5 = 24 / 5 =
4.8
P4 P1 P3 P5 P2
0 6 12
9
7 16
COMPLETION
TIME (CT)
ADVANTAGE & DISADVANTAGE OF
SJF
Advantage:
1. Shortest jobs are favored.
2. It is probably optimal, in that it gives the minimum average waiting
time for a given set of processes.
Disadvantage:
1. SJF may cause starvation if shorter processes keep coming. This
problem is solved by aging.
2. It cannot be implemented at the level of short-term CPU
scheduling.
THANK
YOU

Shortest Job First

  • 1.
    SHORTEST JOB FIRST(SJF) PRESENTED BY NAME:SHUBHAMGUPTA UNIVERSITY ROLL:12000221054 BRANCH:INFORMATION TECHNOLOGY SUBJECT CODE:PCC-CS502
  • 2.
    TOPIC OVERVIEW CPU SCHEDULING PREEMTIVE& NON PREEMPTIVE CLASSIFICATION OF PREEMPTIVE & NON PREEMPTIVE INTRODUCTION OF SHORTEST JOB FIRST(SJF) ALGORITHM OF SJF EXAMPLE OF SJF ADVANTAGE AND DISADVANTAGE OF SJF
  • 3.
    CPU SCHEDULING CPU Schedulingis a process of determining which process will own CPU for execution while another process is on hold. The main task of CPU scheduling is to make sure that whenever the CPU remains idle, the OS at least select one of the processes available in the ready queue for execution. The selection process will be carried out by the CPU scheduler. It selects one of the processes in memory that are ready for execution.
  • 4.
    TYPE OF CPUSCHEDULING Non preemptive –Non-Preemptive scheduling is used when a process terminates , or when a process switches from running state to waiting state. Preemptive –Preemptive scheduling is used when a process switches from running state to ready state or from the waiting state to the ready state. This scheme is known as the Shortest-Remaining-Time- First (SRTF).
  • 5.
    CLASSIFICATION OF PREEMTIVE ANDNON PREEMTIVE CPU SCHEDULING PRE-EMTIVE NON PRE- EMTIVE SRTM LRTM LJF SJF FCFS ROUND ROBIN
  • 6.
    INTRODUCTION OF SHORTESTJOB FIRST(SJF) The shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJN, also known as Shortest Job Next (SJN) It can be preemptive or non-preemptive both. Preemptive SJF is also called Shortest Remaining Time First.
  • 7.
    ALGORITHM OF SJF Sortall the processes according to the arrival time. Then select that process that has minimum arrival time and minimum Burst time. After completion of the process make a pool of processes that arrives afterward till the completion of the previous process and select that process among the pool which is having minimum Burst time.
  • 8.
    BEFORE GOING TOEXAMPLE YOU MUST KNOW THIS TERM Arrival Time: Time at which the process arrives in the ready queue. Completion Time: Time at which process completes its execution. Burst Time: Time required by a process for CPU execution. Turn Around Time: Time Difference between completion time and arrival time. Turn Around Time = Completion Time – Arrival Time Waiting Time(W.T): Time Difference between turn around time and burst time. Waiting Time = Turn Around Time – Burst Time
  • 9.
    EXAMPLE OF NONPREEMPTIVE SJF CONSIDER THE SET OF 5 PROCESSES WHOSE ARRIVAL TIME AND BURST TIME ARE GIVEN BELOW- Process Id Arrival time Burst time P1 3 1 P2 1 4 P3 4 2 P4 0 6 P5 2 3
  • 10.
    GANNT CHART Process Id Arrivaltime Burst time P1 3 1 P2 1 4 P3 4 2 P4 0 6 P5 2 3 P4 P1 P3 P5 P2 0 6 12 9 7 16 COMPLETION TIME (CT)
  • 11.
    Process Id ArrivalTime Burst Time Completio n time Turn around Time(CT-AT) Waiting Time(TAT- BT) P1 3 1 7 7-3 = 4 4-1 = 3 P2 1 4 16 16-1 = 15 15-4 = 11 P3 4 2 9 9-4 = 5 5-2 = 3 P4 0 6 6 6-0 = 6 6-6 = 0 P5 2 3 12 12-2 = 10 10-3 = 7 GANNT CHART Average Turn Around time = (4 + 15 + 5 + 6 + 10) / 5 = 40 / 5 = 8 Average waiting time = (3 + 11 + 3 + 0 + 7) / 5 = 24 / 5 = 4.8 P4 P1 P3 P5 P2 0 6 12 9 7 16 COMPLETION TIME (CT)
  • 12.
    ADVANTAGE & DISADVANTAGEOF SJF Advantage: 1. Shortest jobs are favored. 2. It is probably optimal, in that it gives the minimum average waiting time for a given set of processes. Disadvantage: 1. SJF may cause starvation if shorter processes keep coming. This problem is solved by aging. 2. It cannot be implemented at the level of short-term CPU scheduling.
  • 13.