algorithm to compute waiting time for FCFS scheduling in python

前端 未结 3 1319
庸人自扰
庸人自扰 2021-01-29 10:17

Consider the following code that takes input processes and their arrival times and sort them according to FCFS algorithm, so i\'ve been thinking about algorithms to compute avg

3条回答
  •  深忆病人
    2021-01-29 10:31

    # Author:Geraldo Braho
    process_queue = []
    total_wtime = 0
    n = int(raw_input('Enter the total numbers of processes: '))
    for i in xrange(n):
        process_queue.append([])#append a list object to the list
        process_queue[i].append(raw_input('Enter process name: '))
        process_queue[i].append(int(raw_input('Enter process arrival Time : ')))
        total_wtime += process_queue[i][1]
        process_queue[i].append(int(raw_input('Enter Process CPU bustTime : ')))
        print ''
    
    process_queue.sort(key = lambda process_queue:process_queue[1])
    
    print 'ProcessName\tArrivalTime\tBurstTime'
    for i in xrange(n):
        print process_queue[i][0],'\t\t',process_queue[i][1],'\t\t',process_queue[i][2]
    
    print 'Total waiting time: ',total_wtime
    print 'Average waiting time: ',(total_wtime/n)
    

提交回复
热议问题