# Demo entry 2637939

Non-preemptive

Submitted by Sulekha on Sep 06, 2015 at 20:32
Language: Python. Code size: 2.3 kB.

```fp = open("process.txt" , "r")
proccesses = {}
Wait = []
Running = []
Terminated = 0
i.split(" ")
proccesses[i[0]] = [int(i[2]), int(i[4]) , int(i[6]),0,0] #arrival time, service time, priority, waiting time, hrrn
print (proccesses)
Total_proccesses = len(proccesses)
def schedule():
Terminated = 0
t=0
Waiting_times = []
Finish_times = []
Turnaround_times = []
schedule = []
proccess_x = sorted(proccesses.items() , key = lambda x:x)

while Terminated != Total_proccesses:
for i in range ( 0 , len(proccess_x) ):
proccess = proccess_x[i]
at = proccess_x[i][1][0]
st = proccess_x[i][1][1]
wt = proccess_x[i][1][3]
if (t == at):
print("proccess", proccess, " arriving at ", at)
Wait.append(proccess)
print ("Waiting",Wait, "at time ", t)

if(t == at+st+wt ):
Finish_times.append(t)
Turnaround_times.append(st+wt)
for i in range (0 , len(Wait)) :
Wait[i][1][4] = (Wait[i][1][1]+Wait[i][1][3])/Wait[i][1][1]
print(" Wait list with updated HRRN = " ,Wait, " at time = ", t)
Running.remove(proccess)
Terminated = Terminated + 1
schedule.append(proccess[0])
Waiting_times.append(wt)
t = t+1
if (len(Wait)!=0 and len(Running) == 0):
HRRN()
Running.append(Wait[0])
Wait.pop(0)
for i in range (0 , len(Wait)) :
Wait[i][1][3] += 1

print("ProccessID  Waiting time   Finish Time   Turnaround Time")
for i in range(0,len(proccess_x)):
print (schedule[i],"           ", Waiting_times[i], "            ",Finish_times[i], "            ",Turnaround_times[i])

def FCFS():
Wait.sort(key=lambda x:x[1][0])
def SJF():
Wait.sort(key=lambda x:x[1][1])
def Priority():
Wait.sort(key = lambda x:x[1][2])
def HRRN():
Wait.sort(key=lambda x:x[1][4], reverse=True)

schedule()
```

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.