Lab Report
Lab Report
I)Gantt chart:
P1 P2 P3
0 18 21 24
II)
Total waiting time = 36
Average waiting time = 36/3 = 12
III)
Total turn around time = 60
Average turn around time=60/3 =20
IV.
Total completion time=63
Average completion time =63/3 = 21
Program Code:
def fcfs_scheduling():
print("FIRST COME FIRST SERVE SCHEDULING")
n = int(input("Enter number of processes: "))
processes = []
for i in range(1, n + 1):
arrival_time = int(input(f"Enter arrival time of process P{i}: "))
burst_time = int(input(f"Enter burst time of process P{i}: "))
processes.append((f"P{i}", arrival_time, burst_time))
processes.sort(key=lambda x: x[1]) # Sort processes based on arrival time
exit_time = [0] * n
turnaround_time = [0] * n
waiting_time = [0] * n
gantt_chart = []
for i in range(n):
if i == 0:
exit_time[i] = processes[i][2]
else:
exit_time[i] = exit_time[i - 1] + processes[i][2]
gantt_chart.append((processes[i][0], exit_time[i]))
avg_waiting_time = sum(waiting_time) / n
avg_turnaround_time = sum(turnaround_time) / n
avg_completion_time = sum(exit_time) / n
print("\nGantt Chart:")
print("-" * 40)
for entry in gantt_chart:
print(f"| {entry[0]} ", end="")
print("|")
print("-" * 40)
for entry in gantt_chart:
print(f"| {entry[1]:<2} ", end="")
print(f"|\n{'-' * 40}")
Result:
Conclusion: FCFS provides an efficient, simple and error-free process scheduling
algorithm that saves valuable CPU resources. The algorithm may be affected by
the convoy effect, where short processes are delayed behind long ones, leading to
inefficient use of the CPU. Also FCFS may not be appropriate for a realistic
scenario with diverse process characteristics, as it can lead to inefficient use of
CPUs and prolonged turnaround time.