Os Lab 12 SRTF
Os Lab 12 SRTF
Operating Systems
Experiment 12
Shortest Remaining Time First (SJF-Preemptive) CPU Scheduling
Algorithm
1. The choice of preemptive and non preemptive arises when a new process arrives at the
ready queue and a previous process is not finished and is being executed. If the next CPU
burst of new process is shorter than current executing process, then in preemptive
version , it will stop that process and will start executing the newly arrived process.
2. While, in non preemptive version of SJF, even if the arriving process is shorter than
currently executing process, current process is not stopped . After the current process
finishes , then the new process gets in the queue. This is the key difference between
preemptive and preemptive version of SJF.
3. The current state of the process is saved by the context switch and the CPU is given to
another process.
Note – If 2 processes have same execution time, then jobs are based on First Come First Serve
Basis.
Advantages-
SRTF is optimal and guarantees the minimum average waiting time.
It provides a standard for other algorithms since no other algorithm performs better than
it.
Disadvantages-
It can not be implemented practically since burst time of the processes can not be known
in advance.
It leads to starvation for processes with larger burst time.
Problem-01:
Consider the set of 3 processes whose arrival time and burst time are given below:
P1 0 9
P2 1 4
P3 2 9
If the CPU scheduling policy is SRTF, calculate the average waiting time and average turn around
time.
Gantt Chart- The order in which the CPU processes the process are (Gantt Chart)
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
1. At ( t =0ms ), P1 arrives. It’s the only process so CPU starts executing it.
executed .
3ms. As ,P2 and P4 have same time, so the task which came first will be executed
Waiting time
LAB TASK
If the CPU scheduling policy is SJF preemptive (SRTF), calculate the average waiting time and
average turnaround time and create the Gantt chart in output
Output: