-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcfs_update.py
More file actions
48 lines (37 loc) · 1.41 KB
/
fcfs_update.py
File metadata and controls
48 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class FcFs:
def findWaitingTime(self, processes, n, bt, wt, at):
service_time = [0] * n
service_time[0] = min(at)
wt[0] = 0
# calculating waiting time
for i in range(1, n):
# Add burst time of previous processes
service_time[i] = (service_time[i - 1] +
bt[i - 1])
# Find waiting time for current
# process = sum - at[i]
wt[i] = service_time[i] - at[i]
# If waiting time for a process is in
# negative that means it is already
# in the ready queue before CPU becomes
# idle so its waiting time is 0
if (wt[i] < 0):
wt[i] = 0
# Function to calculate turn around time
def findTurnAroundTime(self, 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 waiting
# and turn-around times.
def findavgTime(self, processes, n, bt, at):
wt = [0] * n
tat = [0] * n
# Function to find waiting time
# of all processes
self.findWaitingTime(processes, n, bt, wt, at)
# Function to find turn around time for
# all processes
self.findTurnAroundTime(processes, n, bt, wt, tat)
return wt, tat, at, bt