0% found this document useful (0 votes)
26 views2 pages

Aim: Write A Program To Implement First-Come First-Served (FCFS) Process

The document describes a program to implement the first-come first-served (FCFS) process scheduling algorithm. It includes the code for the FCFS class with methods for preprocessing, calculating completion times, turnaround times, and waiting times to output average times.

Uploaded by

Shub
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)
26 views2 pages

Aim: Write A Program To Implement First-Come First-Served (FCFS) Process

The document describes a program to implement the first-come first-served (FCFS) process scheduling algorithm. It includes the code for the FCFS class with methods for preprocessing, calculating completion times, turnaround times, and waiting times to output average times.

Uploaded by

Shub
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/ 2

Program No.

1 Program name: FCFS Algorithm

Aim : Write a program to implement first-come first-served ( FCFS ) process


scheduling algorithm.

Source Code

class FCFS(object):

def __init__(self,d,avg_tat,avg_wt):
self.d=d
self.avg_tat=avg_tat
self.avg_wt=avg_wt
def preprocess(self):
sorted_tuples = sorted(self.d.items(), key=lambda item: item[1][-1])
self.d = {k: v for k, v in sorted_tuples}

def completion_time(self):
self.d[list(self.d.keys())[0]].append(self.d[list(self.d.keys())[0]]
[0]+0) #Initial waiting time is zero
for i in range(1,len(self.d)):
self.d[list(self.d.keys())[i]].append(self.d[list(self.d.keys())[i]]
[0]+self.d[list(self.d.keys())[i-1]][2])

def turn_around_time(self):
for i in range(0,len(self.d)):
self.d[list(self.d.keys())[i]].append(self.d[list(self.d.keys())[i]]
[2]-self.d[list(self.d.keys())[i]][1])

for i in self.d:
self.avg_tat +=self.d[i][3]

self.avg_tat/=len(self.d)
return self.avg_tat
def waiting_time(self):
for i in range(0,len(self.d)):
self.d[list(self.d.keys())[i]].append(self.d[list(self.d.keys())[i]]
[3]-self.d[list(self.d.keys())[i]][0])
print(self.d)
for i in self.d:
self.avg_wt +=self.d[i][-1]
self.avg_wt/=len(self.d)

return self.avg_wt

if __name__=="__main__":
p = list(map(str, input("Enter the processes: ").split()))
print(p)
np = len(p)

d = dict.fromkeys(p,0)

print("Enter the burst times of processes: ")


bt = list(map(int, input().split()))

Enroll. No.: 03696302718 Name: Shubham Sharma


Program No.1 Program name: FCFS Algorithm

print("Enter the arrival times of processes: ")


at = list(map(int, input().split()))
j=0
for i in d:
d[i]=[bt[j],at[j]]
j=j+1

fc = FCFS(d,0,0)
fc.preprocess()
fc.completion_time()
print(f'Average turn around time is : {fc.turn_around_time()}')
print(f'Average waiting time is : {fc.waiting_time()}')

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Output

Enroll. No.: 03696302718 Name: Shubham Sharma

You might also like