FCFS Scheduling Program in Python

FCFS Scheduling Program in Python. First Come, First Served (FCFS) is one of the simplest and most Straightforward CPU Scheduling Algorithms. As the name suggests, the algorithm schedules the processes in the order they arrived in the ready queue. This article will walk you through creating an FCFS scheduling Program in Python.

FCFS Scheduling Algorithm Steps

The steps for the FCFS scheduling algorithm are as follows:

  • Input the process along with their burst times.
  • Sort the Processes by their arrival time.
  • Compute the start and finish times for each process.
  • Calculate the waiting time and turnaround time for each process.
  • Compute the average waiting time and turnaround time.

FCFS Python Implementation

Here is a Python implementation of the FCFS Scheduling Algorithm:

Defining the Process Class

Let’s define a class that represents a process. Each process will have attributes like Process ID, arrival time, and burst time.

Example and Explanation

Let’s break down the example provided in the Above Python code

  • Process initialization: We created a list of processes with their respective arrival and burst times.
  • Scheduling: The fcfs_scheduling function sorts the processes by their arrival time and calculates the start time, finish time, waiting time, and turnaround time for each process.
  • Output: The print_processes function prints the details of each process.

Output

FCFS Scheduling in Python

Explanation

  • Process 1 arrives at time 0 and starts immediately, finishing at time 4.
  • Process 2 arrives at time 1 but wait until process 1 finishes. It starts at time 4 and finishes at time 7.
  • Process 3 arrives at time 2 and waits for processes 1 and 2 to finish, starting at time 7 and finishing at time 8.
  • Process 4 arrives at time 4 and waits for all previous processes to finish, starting at time 8 and finishing at time 10.

The FCFS scheduling algorithm is simple to implement but may not always be efficient due to potential long waiting times for shorter processes.

Happy Coding and Learning

See Also

Leave a Comment