0% found this document useful (0 votes)
69 views

Python Program For Implementation FCFS Scheduling Akash

Uploaded by

Akash Baghel
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)
69 views

Python Program For Implementation FCFS Scheduling Akash

Uploaded by

Akash Baghel
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

# Python program for implementation FCFS scheduling

# Function to find the waiting


# time for all processes
def findWaitingTime(processes, n,bt, wt):

# waiting time for


# first process is 0
wt[0] = 0

# calculating waiting time


for i in range(1, n ):
wt[i] = bt[i - 1] + wt[i - 1]

# Function to calculate turn


# around time
def findTurnAroundTime(processes, n, bt, wt, tat):

# calculating turnaround
# time by adding bt[i] + wt[i]
for i in range(n):
tat[i] = bt[i] + wt[i]

# Function to calculate
# average time
def findavgTime( processes, n, bt):

wt = [0] * n
tat = [0] * n
total_wt = 0
total_tat = 0

# Function to find waiting


# time of all processes
findWaitingTime(processes, n, bt, wt)

# Function to find turn around


# time for all processes
findTurnAroundTime(processes, n, bt, wt, tat)

# Display processes along


# with all details
print( "Processes Burst time " +" Waiting time " +" Turn around time")
Akash Baghel
# Calculate total waiting time
# and total turn around time
for i in range(n):

total_wt = total_wt + wt[i]


total_tat = total_tat + tat[i]
print(" " + str(i + 1) + "\t\t" +
str(bt[i]) + "\t " +
str(wt[i]) + "\t\t " +
str(tat[i]))

print( "Average waiting time = "+


str(total_wt / n))
print("Average turn around time = "+
str(total_tat / n))

# Driver code
if __name__ =="__main__":

# process id's
processes = [ 1, 2, 3]
n = len(processes)

# Burst time of all processes


burst_time = [10, 5, 8]

findavgTime(processes, n, burst_time)

OUTPUT

Akash Baghel
# Python program for implementation SJF scheduling

def main():
# Taking the number of processes
n = int(input("Enter number of process: "))
# Matrix for storing Process Id, Burst Time, Average Waiting Time & Average Turn
Around Time.
A = [[0 for j in range(4)] for i in range(100)]
total, avg_wt, avg_tat = 0, 0, 0
print("Enter Burst Time:")
for i in range(n): # User Input Burst Time and alloting Process Id.
A[i][1] = int(input(f"P{i+1}: "))
A[i][0] = i + 1
for i in range(n): # Sorting process according to their Burst Time.
index = i
for j in range(i + 1, n):
if A[j][1] < A[index][1]:
index = j
temp = A[i][1]
A[i][1] = A[index][1]
A[index][1] = temp
temp = A[i][0]
A[i][0] = A[index][0]
A[index][0] = temp
A[0][2] = 0 # Calculation of Waiting Times
for i in range(1, n):
A[i][2] = 0
for j in range(i):
A[i][2] += A[j][1]
total += A[i][2]
avg_wt = total / n
total = 0
# Calculation of Turn Around Time and printing the data.
print("P BT WT TAT")
for i in range(n):
A[i][3] = A[i][1] + A[i][2]
total += A[i][3]
print(f"P{A[i][0]} {A[i][1]} {A[i][2]} {A[i][3]}")
avg_tat = total / n
print(f"Average Waiting Time= {avg_wt}")
print(f"Average Turnaround Time= {avg_tat}")

if __name__ == "__main__":
main()

OUTPUT

Akash Baghel

You might also like