0% found this document useful (0 votes)
149 views4 pages

Program For SRTF Algorithm

The document describes an algorithm for Shortest Remaining Time First (SRTF) scheduling. It defines functions to find the waiting time and turnaround time of each process. It then calculates and prints the average waiting time and average turnaround time for a sample set of processes.

Uploaded by

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

Program For SRTF Algorithm

The document describes an algorithm for Shortest Remaining Time First (SRTF) scheduling. It defines functions to find the waiting time and turnaround time of each process. It then calculates and prints the average waiting time and average turnaround time for a sample set of processes.

Uploaded by

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

PROGRAM FOR SRTF ALGORITHM

def findWaitingTime(processes, n, wt):

rt = [0] * n

for i in range(n):

rt[i] = processes[i][1]

complete = 0

t=0

minm = 999999999

short = 0

check = False

while (complete != n):

for j in range(n):

if ((processes[j][2] <= t) and

(rt[j] < minm) and rt[j] > 0):

minm = rt[j]

short = j

check = True

if (check == False):

t += 1

continue

rt[short] -= 1
minm = rt[short]

if (minm == 0):

minm = 999999999

if (rt[short] == 0):

complete += 1

check = False

fint = t + 1

wt[short] = (fint - proc[short][1] -

proc[short][2])

if (wt[short] < 0):

wt[short] = 0

t += 1

def findTurnAroundTime(processes, n, wt, tat):

for i in range(n):

tat[i] = processes[i][1] + wt[i]

def findavgTime(processes, n):

wt = [0] * n

tat = [0] * n

findWaitingTime(processes, n, wt)

findTurnAroundTime(processes, n, wt, tat)

print("Processes Burst Time Waiting",

"Time Turn-Around Time")


total_wt = 0

total_tat = 0

for i in range(n):

total_wt = total_wt + wt[i]

total_tat = total_tat + tat[i]

print(" ", processes[i][0], "\t\t",

processes[i][1], "\t\t",

wt[i], "\t\t", tat[i])

print("\nAverage waiting time = %.5f "%(total_wt /n) )

print("Average turn around time = ", total_tat / n)

if __name__ =="__main__":

proc = [[1, 6, 1], [2, 8, 1],

[3, 7, 2], [4, 3, 3]]

n=4

findavgTime(proc, n)
OUTPUT:

P BT WT TAT

1 6 7 13

2 2 0 2

3 8 14 22

4 3 0 3

5 4 2 6

Average waiting time = 4.6

Average turn around time = 9.2

You might also like