0% found this document useful (0 votes)
28 views1 page

Python FCFS Scheduling Algorithm

The document presents a Python program for First-Come, First-Served (FCFS) scheduling. It defines a function to calculate completion, turnaround, and waiting times for a set of processes based on their burst times. The program also includes a Gantt chart representation of the scheduling results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

Python FCFS Scheduling Algorithm

The document presents a Python program for First-Come, First-Served (FCFS) scheduling. It defines a function to calculate completion, turnaround, and waiting times for a set of processes based on their burst times. The program also includes a Gantt chart representation of the scheduling results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name: Kassim Boluwatife Ayodeji

Matric number: 23120102054


Dept: Computer science Education ([Link])

USING PYTHON PROGRAM(FCFS SCHEDULING)

def fcfs_scheduling(processes, burst_times):


n = len(processes)

# Initialize variables
waiting_times = [0] * n
turnaround_times = [0] * n
completion_times = [0] * n

# Calculate Completion Time


completion_times[0] = burst_times[0]
for i in range(1, n):
completion_times[i] = completion_times[i - 1] + burst_times[i]

# Calculate Turnaround Time and Waiting Time


for i in range(n):
turnaround_times[i] = completion_times[i] # TAT = CT - Arrival (Arrival = 0 in this
example)
waiting_times[i] = turnaround_times[i] - burst_times[i]

# Print the results


print("Process\tBurst Time\tCompletion Time\tTurnaround Time\tWaiting Time")
for i in range(n):
print(

f"{processes[i]}\t{burst_times[i]}\t\t{completion_times[i]}\t\t{turnaround_times[i]}\t\t{waiting_ti
mes[i]}"
)

# Gantt Chart Representation


print("\nGantt Chart:")
print(" | ".join(f"P{processes[i]}" for i in range(n)))
print("0", end="")
for ct in completion_times:
print(f"

You might also like