def main(a,b,c,d,e): global pmem, smem, processlist, timeout, secmem, la, lb, frametable, cptr, algochoice,pf_enable,opt_list,proc_start,proc_end,dataset_start pmemsize=int(b) #pmemsize=int(input("Enter the no. of physical memory page frames: ")) # -------- 1st input -------- assert pmemsize>0, "Primary memory size must be a positive integer" pmem, smem=Memory(pmemsize), Memory(128) #creation of primary and secondary memory objects #processlist=[Process(open('cmd.txt')), Process(open('cmd2.txt')), Process(open('cmd3.txt')), Process(open('cmd4.txt'))] #processlist is a list of all the processes that are to be executed for x in range(pmemsize): frametable.append((None, 0)) cptr=0 '''proglist=['cmd.txt','cmd2.txt','cmd3.txt','cmd4.txt'] t=int(input("Enter the number of processes to run (maximum 4 for now): ")) # -------- 2nd input -------- assert 1<=t<=4, "Number of processes must fall within range" proglist=proglist[:t]''' processlist=[] proglist=a for i in proglist: processlist.append(Process(open(i))) secmem=copy.deepcopy(dict(smem)) """ This simulator can run any number of processes (not just 4), provided the programs are available and have been written with MU0 instructions which are syntactically correct """ timeout=int(c) #timeout=int(input("Enter timeout period (period after which a process is switched): ")) # -------- 3rd input -------- assert timeout>0, "Timeout period must be a positive integer" #print() '''for i in range(3, 0, -1): print('Starting in %d...\a\r'%i, end="") time.sleep(1)''' #print() '''algochoice=int(input("Choose replacement algorithm {}: ".format(repalgo))) assert 1<=algochoice<=4, "Invalid choice"''' algochoice=d if algochoice==5: import opt_module programlist=[x.name for x in processlist] opt_list=opt_module.main(pmemsize, programlist, timeout) if algochoice!=3: #Clock algorithm works with demand paging only #pf_enable=1 if input("Enable prefetching [y/n]? ").lower() in ['y', 'ye', 'yes'] else 0 pf_enable=int(e) if pf_enable: print('\n--------------------------------------\n') print('''An assumption will be made that all instructions take only one processor cycle regardless of their nature.''') print('\n--------------------------------------\n') executeprocesses() #call the subroutine to execute required number of processes la=[x for x in la if x != []] lb=[x for x in lb if x != []] for i in processlist: proc_start.append(i.start) proc_end.append(i.end) dataset.append(i.datalist)
def main(a, b, c, d, e): global pmem, smem, processlist, timeout, secmem, la, lb, frametable, cptr, algochoice, pf_enable, opt_list, proc_start, proc_end, dataset_start pmemsize = int(b) #pmemsize=int(input("Enter the no. of physical memory page frames: ")) # -------- 1st input -------- assert pmemsize > 0, "Primary memory size must be a positive integer" pmem, smem = Memory(pmemsize), Memory( 128) #creation of primary and secondary memory objects #processlist=[Process(open('cmd.txt')), Process(open('cmd2.txt')), Process(open('cmd3.txt')), Process(open('cmd4.txt'))] #processlist is a list of all the processes that are to be executed for x in range(pmemsize): frametable.append((None, 0)) cptr = 0 '''proglist=['cmd.txt','cmd2.txt','cmd3.txt','cmd4.txt'] t=int(input("Enter the number of processes to run (maximum 4 for now): ")) # -------- 2nd input -------- assert 1<=t<=4, "Number of processes must fall within range" proglist=proglist[:t]''' processlist = [] proglist = a for i in proglist: processlist.append(Process(open(i))) secmem = copy.deepcopy(dict(smem)) """ This simulator can run any number of processes (not just 4), provided the programs are available and have been written with MU0 instructions which are syntactically correct """ timeout = int(c) #timeout=int(input("Enter timeout period (period after which a process is switched): ")) # -------- 3rd input -------- assert timeout > 0, "Timeout period must be a positive integer" #print() '''for i in range(3, 0, -1): print('Starting in %d...\a\r'%i, end="") time.sleep(1)''' #print() '''algochoice=int(input("Choose replacement algorithm {}: ".format(repalgo))) assert 1<=algochoice<=4, "Invalid choice"''' algochoice = d if algochoice == 5: import opt_module programlist = [x.name for x in processlist] opt_list = opt_module.main(pmemsize, programlist, timeout) if algochoice != 3: #Clock algorithm works with demand paging only #pf_enable=1 if input("Enable prefetching [y/n]? ").lower() in ['y', 'ye', 'yes'] else 0 pf_enable = int(e) if pf_enable: print('\n--------------------------------------\n') print('''An assumption will be made that all instructions take only one processor cycle regardless of their nature.''') print('\n--------------------------------------\n') executeprocesses( ) #call the subroutine to execute required number of processes la = [x for x in la if x != []] lb = [x for x in lb if x != []] for i in processlist: proc_start.append(i.start) proc_end.append(i.end) dataset.append(i.datalist)
This simulator can run any number of processes, provided the programs are available and have been written with MU0 instructions and are syntactically correct """ timeout=int(input("Enter timeout period (period after which a process is switched): ")) # -------- 3rd input -------- assert timeout>0, "Timeout period must be a positive integer" algochoice=int(input("Choose replacement algorithm {}: ".format(repalgo))) assert 1<=algochoice<=5, "Invalid choice" if algochoice==5: import opt_module programlist=[x.name for x in processlist] opt_list=opt_module.main(pmemsize, programlist, timeout) if algochoice!=3: #Clock algorithm works with demand paging only pf_enable=1 if input("Enable prefetching [y/n]? ").lower() in ['y', 'ye', 'yes', 'yeah', 'yep'] else 0 """ An assumption will be made that all instructions take only one processor cycle regardless of their nature. """ executeprocesses() #call the subroutine to execute required number of processes # -----------------------------------------------------------------------------------
and have been written with MU0 instructions and are syntactically correct """ timeout = int( input( "Enter timeout period (period after which a process is switched): " )) # -------- 3rd input -------- assert timeout > 0, "Timeout period must be a positive integer" algochoice = int(input( "Choose replacement algorithm {}: ".format(repalgo))) assert 1 <= algochoice <= 5, "Invalid choice" if algochoice == 5: import opt_module programlist = [x.name for x in processlist] opt_list = opt_module.main(pmemsize, programlist, timeout) if algochoice != 3: #Clock algorithm works with demand paging only pf_enable = 1 if input("Enable prefetching [y/n]? ").lower() in [ 'y', 'ye', 'yes', 'yeah', 'yep' ] else 0 """ An assumption will be made that all instructions take only one processor cycle regardless of their nature. """ executeprocesses( ) #call the subroutine to execute required number of processes # -----------------------------------------------------------------------------------