0% found this document useful (0 votes)
17 views5 pages

Os Lab 12 SRTF

The document describes the Shortest Remaining Time First (SRTF) CPU scheduling algorithm. It provides details on how SRTF works, its advantages and disadvantages. It also includes an example problem to calculate average waiting time and turnaround time for 3 processes under SRTF scheduling and to draw the corresponding Gantt chart.

Uploaded by

ayeshalatif0003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Os Lab 12 SRTF

The document describes the Shortest Remaining Time First (SRTF) CPU scheduling algorithm. It provides details on how SRTF works, its advantages and disadvantages. It also includes an example problem to calculate average waiting time and turnaround time for 3 processes under SRTF scheduling and to draw the corresponding Gantt chart.

Uploaded by

ayeshalatif0003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

Operating Systems
Experiment 12
Shortest Remaining Time First (SJF-Preemptive) CPU Scheduling
Algorithm

CLO 2. Use modern tools and languages.


CLO 3. Demonstrate an original solution of problem under discussion.
CLO 4. Work individually as well as in teams
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

Shortest Remaining Time First (SRTF)


(SJF-Preemptive)
SJF:

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.

Shortest Remaining Time First (SRTF) Preemptive


If a new process arrives with CPU burst length less than remaining time of current executing
process, preempt. This scheme is known as the Shortest-Remaining-Time-First (SRTF).
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

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.

 Priorities can not be set for the processes.

 Processes with larger burst time have poor response time.

Problem-01:
Consider the set of 3 processes whose arrival time and burst time are given below:

Process Id Arrival time Burst time

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

SOFTWARE ENGINEERING DEPARTMENT

ALGORITHM for SRTF (SJF-Preemptive):

1. At ( t =0ms ), P1 arrives. It’s the only process so CPU starts executing it.

2. At ( t = 1ms ), P2 has arrived . At this time, P1 (remaining time ) = 5 ms . P2 has

4ms , so as P2 is shorter, P1 is preempted and P2 process starts executing.

3. At ( t = 2ms ), P3 process has arrived. At this time, P1(remaining time) = 5ms,

P2(remaining time ) = 3 ms , P3 = 2ms. Since P3 is having least burst time, P3 is

executed .

4. At ( t = 3ms ), P4 comes , At this time, P1 = 5ms, P2 = 3ms, P3 = 1ms, P4 = 3ms. Since

P4 does not have short burst time, so P3 continues to execute.

5. At ( t= 4ms ),P3 is finished . Now, remaining tasks are P1 = 5ms, P2 = 3ms, P4 =

3ms. As ,P2 and P4 have same time, so the task which came first will be executed

first. So, P2 gets executed first.

6. At ( t = 7ms ),P4 gets executed for 3ms.


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

7. At ( t = 10ms ), P1 gets executed till it finishes.

Waiting time

Completion time – Burst Time – Arrival Time

1. P1 waiting time = (15-6-0) = 9ms


2. P2 waiting time = (7-4-1) = 2ms
3. P3 waiting time = (4-2-2 )=0ms
4. P4 waiting time = (10-3-3)= 4ms
5. The average waiting time is ( 9 +2 + 0 + 4)/4 = 15/4 = 3.75

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy