def run(select, verbose, wait_time=0.0, amount=100): global f, s # clear_fcfs() # clear (previous) FCFS select results # clear_sjf() # clear (previous) SJF select results if select != "none": prepare(select, amount) if select.lower() == "fcfs": w = load(select) f = fcfs(w, wait_time, verbose) elif select.lower() == "sjf": w = load(select) s = sjf(w, wait_time, verbose) elif select.lower() == "both": w = load(select) f = fcfs(w, wait_time, verbose) w = load(select) s = sjf(w, wait_time, verbose) elif select.lower() == "none": pass else: exit(1) return [f, s]
def case_fcfs(timestamp): if not cfg["SUB"]["USE_RR_TO_FCFS"]: fcfs_list_of_processes = generate_processes( cfg["FCFS"]["PROCESS_RANGE"], cfg["FCFS"]["ARRIVAL_RANGE"], cfg["FCFS"]["DURATION_RANGE"]) reason_generated = 'FCFS_GENERATED' reason_sorted = 'FCFS_SORTED' # before sorting, raw generated if cfg["EXE"]["TXT"]: save_processes(reason_generated, fcfs_list_of_processes, timestamp) # after sorting by arrival_time list_of_processes_FCFS = prepare_processes_list(fcfs_list_of_processes) if cfg["EXE"]["TXT"]: save_processes(reason_sorted, list_of_processes_FCFS, timestamp) else: # copy previous generated list_of_processes_FCFS = deepcopy(list_of_processes) list_of_processes_FCFS = prepare_processes_list(list_of_processes_FCFS) # execute the algorithm fcfs_result = fcfs(list_of_processes_FCFS) # save results if cfg["EXE"]["TXT"]: save_processes('FCFS_DONE', fcfs_result, timestamp) # make a plot if cfg["EXE"]["GRAPHS"]: fcfs_plot(fcfs_result, timestamp)
def calculate(self): pd = dict() r= self.ptable.rowCount() for i in range(r): # getting all the data from the table in a dictoinary-list. pd[str(i+1)]=[int(self.ptable.item(i,1).text()), int(self.ptable.item(i,2).text()),\ int(self.ptable.item(i,3).text())] print(pd) # calling the corresponding function: selected = self.algoselect.currentText() if selected == "First Come First Served": fcfsdict,pLine,avgwait,avgturntime = fcfs.fcfs(pd) print("in design: ",fcfsdict) self.printData(pd,fcfsdict,pLine,avgwait,avgturntime,'First Come First Serve') elif selected == "Shortest Job First: Preemptive": sjfpredict,pLine,avgwait,avgturntime = sjfpre.sjfpre(pd) self.printData(pd,sjfpredict,pLine,avgwait,avgturntime,'Shortest Job First: Preemptive') elif selected == "Shortest Job First: Non-Preemptive": sjfnonpredict,pLine,avgwait,avgturntime = sjfnonpre.sjfnonpre(pd) self.printData(pd,sjfnonpredict,pLine,avgwait,avgturntime,'Shortest Job First: Non-Preemptive') elif selected == "Priority Scheduling: Preemptive": priopredict,pLine,avgwait,avgturntime = prioritypre.priopre(pd) self.printData(pd,priopredict,pLine,avgwait,avgturntime,'Priority Scheduling: Preemptive') elif selected == "Priority Scheduling: Non-Preemptive": priononpredict,pLine,avgwait,avgturntime = prioritynonpre.priononpre(pd) self.printData(pd,priononpredict,pLine,avgwait,avgturntime,'Priority Scheduling: Non-Preemptive') elif selected == "All": returndict,pLine,avgwait,avgturntime=[1 for i in range(5)],\ [1 for i in range(5)],[1 for i in range(5)],[1 for i in range(5)] returndict[0],pLine[0],avgwait[0],avgturntime[0] = fcfs.fcfs(pd) returndict[1],pLine[1],avgwait[1],avgturntime[1] = sjfpre.sjfpre(pd) returndict[2],pLine[2],avgwait[2],avgturntime[2] = sjfnonpre.sjfnonpre(pd) returndict[3],pLine[3],avgwait[3],avgturntime[3] = prioritypre.priopre(pd) returndict[4],pLine[4],avgwait[4],avgturntime[4] = prioritynonpre.priononpre(pd) # print("returned values:",returndict,'\n',pLine,'\n',avgturntime,'\n',avgwait) print('average turns: ',avgturntime) minturnindx = avgturntime.index(min(avgturntime)) self.printData(pd,returndict[minturnindx],pLine[minturnindx],avgwait[minturnindx],\ avgturntime[minturnindx], self.algoselect.itemText(minturnindx+1))
def main(): proc_num = 4 rondas = 2 # Si el usuario pasa mal los parametros ponemos unos por defecto if len(sys.argv) == 3: proc_num = int(sys.argv[1]) rondas = int(sys.argv[2]) else: print( "Algo salió mal con los param. así que usaremos unos por defecto") print("Número de procesos : %d" % proc_num) print("Número de rondas : %d" % rondas) for ronda in range(0, rondas): print("----------------------------------------------\n") print("RONDA %d \n" % (ronda + 1)) print("Los procesos generados aleatoriamente son :") procesos = rand_proc(proc_num) for j in procesos: print("id: %d, t_arrived = %d, t = %d" % (j[0], j[1], j[2])) print("Realizando fcfs...") # Pasando una copia de procesos a fcfs... fcfs([sublista[:] for sublista in procesos[:]]) print("Realizando Round Robin...") # Pasando una copia de procesos a spn... round_robin([sublista[:] for sublista in procesos[:]]) print("Realizando Round Robin 4...") # Pasando una copia de procesos a spn... round_robin4([sublista[:] for sublista in procesos[:]], 4) print("Realizando spn...") # Pasando una copia de procesos a spn... spn([sublista[:] for sublista in procesos[:]])
def main(): # Original bursts = [ ['P1', [5, 27, 3, 31, 5, 43, 4, 18, 6, 22, 4, 26, 3, 24, 4]], ['P2', [4, 48, 5, 44, 7, 42, 12, 37, 9, 76, 4, 41, 9, 31, 7, 43, 8]], [ 'P3', [8, 33, 12, 41, 18, 65, 14, 21, 4, 61, 15, 18, 14, 26, 5, 31, 6] ], ['P4', [3, 35, 4, 41, 5, 45, 3, 51, 4, 61, 5, 54, 6, 82, 5, 77, 3]], [ 'P5', [ 16, 24, 17, 21, 5, 36, 16, 26, 7, 31, 13, 28, 11, 21, 6, 13, 3, 11, 4 ] ], ['P6', [11, 22, 4, 8, 5, 10, 6, 12, 7, 14, 9, 18, 12, 24, 15, 30, 8]], ['P7', [14, 46, 17, 41, 11, 42, 15, 21, 4, 32, 7, 19, 16, 33, 10]], ['P8', [4, 14, 5, 33, 6, 51, 14, 73, 16, 87, 6]] ] data = Data() # initialize ready_queue and wait for p in bursts: data.mlfq[0].append(p + [0]) data.ready_queue.append(p) data.wait[p[0]] = 0 data.turn_around[p[0]] = 0 data.response[p[0]] = -1 # Choose which algorithm to perform fcfs(data) # sjf(data) # mlfq(data) print_finished(data) print_gantt_chart(data)
try: with open(x, "r") as f: process = f.read().splitlines( ) # Split each line from the file and append to process except: # Exception handling to when file reading fails print("Error opening file") exit() n = len(process) # length of process list for i in range(n): p.append(process[i].split( ' ')) # Splitting each process line in terms of spaces f.close() # Closing the input file return p # Return the parsed process data list # Loop to iterate infinitely and execute processes as per given operation while (True): print("Enter required operation") print("1: FCFS", "2: SJF", "3: RR", "4:EXIT", sep='\n') cmd = input() if cmd == '1': fcfs(readFile()) elif cmd == '2': sjf(readFile()) elif cmd == '3': rr() else: exit()
def main(): # Error handling for the arguments if len(sys.argv) != 8 and len(sys.argv) != 9: sys.exit("ERROR: Incorrect number of arguments!") try: # Seed for the random number generator to determine the interarrival times of CPU bursts. number_generator_seed = int(sys.argv[1]) # Lambda value that determines average value generated for interarrival times # (with exponential distribution). lambda_value = float(sys.argv[2]) # Upper-bound for valid pseudo-random values (will skip values greater than upper bound). upper_bound = int(sys.argv[3]) # Number of processes to simulate. # Process IDs are assigned in alphabetical order A through Z, therefore atmost there will # be 26 processes to simulate. number_simulations = int(sys.argv[4]) # Time (in milliseconds) it takes to perform a context switch. context_switch_time = int(sys.argv[5]) # For SJF and SRT, we cannot know the actual CPU burst times beforehand, so we will make # an estimate determined via exponential averaging (using "ceiling" function). alpha_value = float(sys.argv[6]) # For the RR algoorithm, we need to define the time slice value (in milliseconds). time_slice = int(sys.argv[7]) except ValueError: sys.exit("ERROR: Improper arguments were given!") # For the RR algorithm, we define whether processes or added to the beginning or end of # the ready queue when they arrive or complete I/O. # Value should be set to BEGINNING or END, with END being the default behavior. if len(sys.argv) > 8: if sys.argv[8] == "BEGINNING" or sys.argv[8] == "END": queue_addition = sys.argv[8] else: sys.exit("ERROR: Enter correct rr_add!") else: queue_addition = "END" # List that contains all of the stimulations processes = [] # List that contains the amount of bursts for each of the processes bursts = [] # List of lists that contains the burst times each burst in each process burst_times = [] # List of lists that contains the I/O times for each burst in each process io_times = [] # Initiating the generator with srand48 generator = Rand48(number_generator_seed) generator.srand48() i = 0 while i < number_simulations: # Adding the arrival times for each process random_number = generator.drand48() arrival_time = math.floor(-math.log(random_number) / lambda_value) # Skip arrival times that exceed upper bound if arrival_time > upper_bound: continue else: # Store the arrival time if it does not exceed upper bound processes.append(arrival_time) # Adding the number of bursts needed for each process random_number = generator.drand48() # Skip bursts that exceed upper bound while math.floor(random_number * 100) + 1 > upper_bound: random_number = generator.drand48() bursts.append(math.floor(random_number * 100) + 1) temp_burst = [] temp_io = [] # For each burst of a process, generate a burst time and an I/O time for j in range(0, bursts[len(bursts)-1]): # Last burst does not have an I/O, so just generate a burst time if j == bursts[len(bursts)-1] - 1: burst_and_io_generator(lambda_value, upper_bound, temp_burst, generator) continue else: # Generating burst time values burst_and_io_generator(lambda_value, upper_bound, temp_burst, generator) # Generating I/O values burst_and_io_generator(lambda_value, upper_bound, temp_io, generator) burst_times.append(temp_burst) io_times.append(temp_io) i += 1 # FCFS Algorithm fcfs(processes, bursts, burst_times, io_times, context_switch_time) print() # SJF Algorithm sjf(processes, bursts, burst_times, io_times, context_switch_time, lambda_value, alpha_value) print() # SRT Algorithm srt(processes, bursts, burst_times, io_times, context_switch_time, lambda_value, alpha_value) print() # RR Algorithm rr(processes, bursts, burst_times, io_times, context_switch_time, time_slice, queue_addition)
from fcfs import fcfs from Priority import Priority from RR import RR from sjf import sjf n=int(input("Enter the number of processes: ")) proc=[] for i in range(n): print("Process: ",i+1,":--") b=int(input("\tEnter Burst time: ")) a=int(input("\tEnter arrival time: ")) p=int(input("\tEnter priority: ")) proc.append([i+1,b,a,p]) quantum =int(input("Enter the Quantum: ")) f=fcfs() p=Priority() r=RR() s=sjf() print("\t\t:: Scheduling Algorithm ::") print("<===============================================>") print("FCFS:") f.findavgTime(proc,n) print("<===============================================>") print("\nSJF:") s.findavgTime(proc, n) print("<===============================================>") print("\nRR:") r.findavgTime(proc, n,quantum) print("<===============================================>") print("\nPriority:") p.priorityScheduling(proc, n)