NEP -OS lAB B.Sc

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 . . .
DOWNLOAD PDF FILE OS LAB MANUAL

 
  
 
 
 PArt B 1.Write a python program to demonstrate FCFS scheduling Algorithm.
  
def calculateTime(n, burst_time): 
	waiting_time = [0] * n 
	turnaround_time = [0] * n 
	avg_waiting_time = 0
	avg_turnaround_time = 0

	waiting_time[0] = 0  

	# Calculating waiting time 
	for i in range(1, n): 
		waiting_time[i] = 0
		for j in range(i): 
			waiting_time[i] += burst_time[j] 

	  
	for i in range(n): 
		turnaround_time[i] = burst_time[i] + waiting_time[i] 
		avg_turnaround_time += turnaround_time[i] 

	avg_turnaround_time /= n 
	print(f"\nAverage Turnaround Time: {avg_turnaround_time}ms") 

	# Calculating average waiting time 
	for i in range(n): 
		avg_waiting_time += waiting_time[i] 

	avg_waiting_time /= n 
	print(f"\nAverage Waiting Time: {avg_waiting_time}ms\n") 

	print("Process\tBurst Time\tWaiting Time\tTurnaround Time") 
	for i in range(n): 
		print(f"P[{i+1}]\t{burst_time[i]}\t\t{waiting_time[i]}\t\t{turnaround_time[i]}") 

# Driver code 
if __name__ == '__main__': 
	n = int(input("Enter total number of processes(maximum 20): ")) 

	burst_time = [] 
	print("\nEnter Process Burst Time") 
	for i in range(n): 
		burst_time.append(int(input(f"P[{i+1}]: "))) 

	calculateTime(n, burst_time) 


Output B1:
Enter total number of processes(maximum 20): 5

Enter Process Burst Time
P[1]: 4
P[2]: 3
P[3]: 4
P[4]: 5
P[5]: 5

Average Turnaround Time: 11.8ms

Average Waiting Time: 7.6ms

Process	Burst Time	Waiting Time	Turnaround Time
P[1]	4		0		4
P[2]	3		4		7
P[3]	4		7		11
P[4]	5		11		16
P[5]	5		16		21