You are on page 1of 5

Usama Kashif

02-134202-032
BSCS-5B

Exercises

Exercise 1

Implement FCFS using


concept of class.
class FCFS:
    def fc():
        TAT = 0
        process = []
        arrival_t = []
        execution_t = []
        waiting_t = [0]
        for i in range(1,6):
            arrival_t.append(input("enter a time :"))
        for i in range(1,6):
            execution_t.append(input("enter e time: "))
        for i in range(1,6):
            process.append(input("enter process: "))
        print("process ",process)
        print("process execution time:",execution_t)
        print("process Arrival Time:",arrival_t)
        for i in range(0,5):
            TAT=TAT+int(execution_t[i])
            waiting_t.append(TAT)

        process="Turnaround time :"+repr(TAT)


        print (process)

FCFS.fc()
Implement SJF.
burst_t = []
process = int(input("number of process: "))
processes = []

for i in range(0,process):
    processes.insert(i,i+1)
print("Enter the burst time of the processess: ")
burst_t = list(map(int,input().split()))

for i in range(0,len(burst_t)-1):
    for j in range(0,len(burst_t)-i-1):
        if(burst_t[j] > burst_t[j+1]):
            temp = burst_t[j]
            burst_t[j] = burst_t[j+1]
            burst_t[j+1] = temp
            processes[j] = processes[j+1]
            processes[j+1] = temp
        
waiting_t = []
average_wt = 0
TAT = []
average_TAT = 0
waiting_t.insert(0,0)
TAT.insert(0,burst_t[0])    
for i in range(1,len(burst_t)):
    waiting_t.insert(i,waiting_t[i-1]+burst_t[i-1])
    TAT.insert(i,waiting_t[i]+burst_t[i])
    average_wt += waiting_t[i]
    average_TAT += TAT[i]
  
average_wt = float(average_wt)/process
average_TAT = float(average_TAT)/process
print("Process\t Burst Time\t Waiting Time\t Turn Around Time")
for i in range(0,process):
    print(str(i)+"\t\t"+str(burst_t[i])+"\t\t"+str(waiting_t[i])+"\t\t"+str(TAT[i]))
  
print("Average Waiting Time: " + str(average_wt))
print("Average TAT: " + str(average_TAT))

Implement RR.

def findWaitingTime(processes, n, bt, wt, quantum):


    rem_bt = [0] * n
 
    for i in range(n):
        rem_bt[i] = bt[i]
    t = 0 # Current time
 
    while(1):
        done = True
        for i in range(n):
            if (rem_bt[i] > 0) :
                done = False # There is a pending process
                if (rem_bt[i] > quantum) :
                    t += quantum
                    rem_bt[i] -= quantum
                else:
                    t = t + rem_bt[i]
                    wt[i] = t - bt[i]
                    rem_bt[i] = 0
        if (done == True):
            break

def findTurnAroundTime(processes, n, bt, wt, tat):


    for i in range(n):
        tat[i] = bt[i] + wt[i]
 
def findavgTime(processes, n, bt, quantum):
    wt = [0] * n
    tat = [0] * n
    findWaitingTime(processes, n, bt,wt, quantum)
    findTurnAroundTime(processes, n, bt,wt, tat)
    print("Processes    Burst Time     Waiting","Time    Turn-Around Time")
    total_wt = 0
    total_tat = 0
    for i in range(n):
 
        total_wt = total_wt + wt[i]
        total_tat = total_tat + tat[i]
        print(" ", i + 1, "\t\t", bt[i],
              "\t\t", wt[i], "\t\t", tat[i])
 
    print("\nAverage waiting time = %.5f "%(total_wt /n) )
    print("Average turn around time = %.5f "% (total_tat / n))
   
processes = []
burst_t = []
process = int(input("enter number of process: "))

for i in range(0,int(process)):
    processes.insert(i,i+1)
print("enter burst time of process: ")  
burst_t = list(map(int,input().split()))
quantum_time = int(input("enter the time quantum: "))

findavgTime(processes,process,burst_t,quantum_time)
Exercise 2

Implement RR with GUI

You might also like