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 6 P5 2 3 Consider the set of 5 processes whose arrival time and burst time are given below-
Gannt chart Process Id Arrival time Burst time P1 3 1 P2 1 4 P3 4 2 P4 6 P5 2 3 P4 P1 P3 P5 P2 6 12 9 7 16 COMPLETION TIME (CT)
Process Id Arrival Time Burst Time Completion 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 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 6 12 9 7 16 COMPLETION TIME (CT)
Advantage & disadvantage of sjf Advantage: Shortest jobs are favored . It is probably optimal, in that it gives the minimum average waiting time for a given set of processes . Disadvantage: SJF may cause starvation if shorter processes keep coming. This problem is solved by aging. It cannot be implemented at the level of short-term CPU scheduling.