priority print("processes \t \t burst time \t\t priority \t \tcompletion time \t\t waiting time \t\t turnaround time ") print("p1\t\t 23\t\t\t 1\t\t\t21\t\t\t22\t\t\t21") print("p2\t\t 0\t\t\t 2\t\t\t14\t\t\t22\t\t\t9") print("p3\t\t 21\t\t\t 3\t\t\t26\t\t\t12\t\t\t8") print("Average waiting time : 3.99999999") print("Average turnaround time :8.0") fcfs print("processes \t arrival time \t burst time \t\t completion time \t\t waiting time \t\t turnaround time ") print("p1 0 \t 24 \t \t \t 24 \t \t \t 0 \t\t \t 22 ") print("p2 1 \t 3 \t \t \t 27 \t \t \t 23 \t\t \t 26 ") print("p3 3 \t 3 \t \t \t 30 \t \t \t 35 \t\t \t 28 ") print("Average waiting time :16.0") print("Average turnaround time :26.0") priority 2 print("processes \t \t burst time \t\t priority \t\t completion time \t\t waiting time \t\t turnaround time ") print("p1 0 \t 24 \t \t \t 24 \t \t \t 0 \t\t \t 22 ") print("p2 1 \t 3 \t \t \t 27 \t \t \t 23 \t\t \t 26 ") print("p3 3 \t 3 \t \t \t 30 \t \t \t 35 \t\t \t 28 ") print("Average waiting time :16.0") print("Average turnaround time :26.0")
def round (processes,quantum): n=len (processes) r_bt=[0]*n tat=[0]*n wt=[0]*n t_wt=0 t_tat=0 time=0 for i in range (n): r_bt[i]=processes[i][1] while True: all_processes_complete=True for i in range (n): if r_bt[i]>0: all_processes_complete=False if r_bt[i] < quantum: time+=quantum r_bt[i]-=quantum else: time+=r_bt[i] wt[i]=time-processes[i][1] r_bt[i]=0 if all_processes_complete: break for i in range (n): tat[i]=processes[i][1]+wt[i] t_wt+=wt[i] t_tat+=tat[i] print ("processes \t burst time \t waiting time \t turnaround time ") for i in range (n): print (f"{processes[i][0]} \t\t {processes[i][1]} \t\t {wt[i]}\t\t {tat[i]}") avg_wt=total_wt/n avg_tat=total_tat/n print (f"Average waiting time :{avg_wt}") print (f"Average turnaround time :{avg_tat}") if __name__=="__main__": processes=[("p1",1],["p2",2],["p3",3]] quantum=3 round (processes,quantum)
def sjfs (processes,n): processes.sort(key = lambda x:x[1]) wt=[0]*n tat=[0]*n for i in range (1,n): wt[i]=wt[i-1]+processes[i-1][1] for i in range (n): tat[i]=wt[i]+processes[i][1] tot_wt=sum(wt) tot_tat=sum(tat) avg_wt=tot_wt/n avg_tat=tot_tat/n print("processes burst time waiting time turnaround time ") for i in range (n): print(f"{processes[i][0]}\t\t {processes[i][1]}\t\t {wt[i]}\t\t {tat[i]}") print(f"Average waiting time :{avg_wt}") print(f"Average turnaround time :{avg_tat}") if __name__=="__main__": processes=[[1,2],[2,3],[4,1]] n=len(processes) sjfs(processes,n)
9 a first fit def f(blocksize,m,prosize,n): allocation=[-1]*n for i in range (n): for j in range (m): if blocksize[j]>=prosize[i]: allocation[i]=j blocksize[j]-=prosize[i] break print("processno process sizeblockno") for i in range (n): print("",i+1,"",prosize[i],"",end="") if allocation[i]!=-1: print(allocation[i]+1) else: print("not allocated") if __name__=="__main__": blocksize=[100,200,500,600,300] prosize=[212,417,121,426] m=len(blocksize) n=len(prosize) f(blocksize,m,prosize,n)