FCFS Scheduling Algorithm: What is, Example Program

โšก Smart Summary

First Come First Serve scheduling runs processes in the exact order they reach the ready queue, using a simple non-preemptive FIFO approach that makes it the easiest CPU scheduling algorithm for an operating system to implement.

  • ๐Ÿ”„ Definition: FCFS assigns the CPU to whichever process requests it first, managing the ready queue as a first-in, first-out (FIFO) structure.
  • โš™๏ธ Nature: FCFS is non-preemptive, so a running process holds the CPU until it finishes its entire burst time.
  • ๐ŸŽŸ๏ธ Analogy: Like a ticket-counter queue, the process that arrives first is served first, and later arrivals wait their turn.
  • ๐Ÿ“Š Calculation: Average waiting time is found by subtracting each process arrival time from its start time, then averaging across all processes.
  • ๐Ÿข Convoy effect: One long process at the front forces shorter jobs to wait, raising average waiting time and hurting performance.
  • ๐Ÿค– AI angle: Machine learning predicts burst times to improve scheduling, and Copilot helps write and test FCFS code quickly.

FCFS Scheduling Algorithm in Operating System

What is First Come First Serve Method?

First Come First Serve (FCFS) is an operating system scheduling algorithm that automatically executes queued requests and processes in order of their arrival. It is the easiest and simplest CPU scheduling algorithm. In this type of algorithm, the process that requests the CPU first gets the CPU allocation first. This is managed with a FIFO queue. The full form of FCFS is First Come First Serve.

As a process enters the ready queue, its PCB (Process Control Block) is linked with the tail of the queue. So, when the CPU becomes free, it is assigned to the process at the beginning of the queue.

Characteristics of FCFS Method

The main characteristics of the First Come First Serve method are listed below:

  • It is a non-preemptive scheduling algorithm, so a process keeps the CPU until it completes its burst time.
  • Jobs are always executed on a first-come, first-serve basis.
  • It is easy to implement and use.
  • This method is poor in performance, and the general wait time is quite high.

Example of FCFS Scheduling

A real-life example of the FCFS method is buying a movie ticket at the ticket counter. In this scheduling algorithm, a person is served according to the queue order. The person who arrives first in the queue buys the ticket first, and then the next one. This continues until the last person in the queue purchases the ticket. Using this algorithm, the CPU process works in a similar manner.

How FCFS Works? Calculating Average Waiting Time

To understand how the algorithm schedules processes, here is an example of five processes arriving at different times. Each process has a different burst time.

Process Burst time Arrival time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Using the FCFS scheduling algorithm, these processes are handled as follows.

Step 1) The process begins with P4, which has arrival time 0.

FCFS scheduling example step 1

Step 2) At time=1, P3 arrives. P4 is still executing. Hence, P3 is kept in a queue.

FCFS scheduling example step 2

Step 3) At time=2, P1 arrives and is kept in the queue.

FCFS scheduling example step 3

Step 4) At time=3, the P4 process completes its execution.

FCFS scheduling example step 4

Step 5) At time=4, P3, which is first in the queue, starts execution.

FCFS scheduling example step 5

Step 6) At time=5, P2 arrives and is kept in a queue.

FCFS scheduling example step 6

Step 7) At time=11, P3 completes its execution.

FCFS scheduling example step 7

Step 8) At time=11, P1 starts execution. It has a burst time of 6, so it completes execution at time interval 17.

FCFS scheduling example step 8

Step 9) At time=17, P5 starts execution. It has a burst time of 4, so it completes execution at time=21.

FCFS scheduling example step 9

Step 10) At time=21, P2 starts execution. It has a burst time of 2, so it completes execution at time interval 23.

FCFS scheduling example step 10

Step 11) Now, let us calculate the average waiting time for the above example.

FCFS scheduling average waiting time

Waiting time = Start time - Arrival time

P4 = 0 – 0 = 0

P3 = 3 – 1 = 2

P1 = 11 – 2 = 9

P5 = 17 – 4 = 13

P2 = 21 – 5 = 16

Average Waiting Time = (0 + 2 + 9 + 13 + 16) / 5 = 40 / 5 = 8

FCFS scheduling average waiting time calculation

Advantages of FCFS

Here are the pros and benefits of using the FCFS scheduling algorithm:

  • It is the simplest form of a CPU scheduling algorithm.
  • It is easy to program.
  • It follows a straightforward first-come, first-served order.

Disadvantages of FCFS

Here are the cons and drawbacks of using the FCFS scheduling algorithm:

  • It is a non-preemptive CPU scheduling algorithm, so once a process has been allocated to the CPU, it will never release the CPU until it finishes executing.
  • The average waiting time is high.
  • Short processes at the back of the queue have to wait for the long process at the front to finish.
  • It is not an ideal technique for time-sharing systems.
  • Because of its simplicity, FCFS is not very efficient.

FAQs

First Come First Serve is a non-preemptive algorithm. Once a process gets the CPU, it runs until its burst finishes, so the scheduler cannot interrupt it to run a newly arrived or shorter process.

The convoy effect happens when several short processes wait behind one long process at the front of the queue. This single long job raises the average waiting time and lowers overall CPU throughput.

Turnaround time equals completion time minus arrival time for each process. It measures the total time a process spends in the system, from its arrival until it finishes execution on the CPU.

FCFS serves by arrival order, Shortest Job First serves the smallest burst first for lower waiting time, and Round Robin gives each process a fixed time slice for time-sharing.

Pure FCFS does not cause starvation, because every process eventually reaches the front of the FIFO queue. However, long jobs can still delay short ones badly through the convoy effect.

FCFS runs in O(n) time when processes are already ordered by arrival, since each is scheduled once. Sorting unsorted arrivals by arrival time first adds an O(n log n) step.

Machine learning models predict process burst times and pick or tune scheduling policies to cut average waiting time and energy use. Researchers apply these AI-driven schedulers in cloud servers and data centers.

Yes. GitHub Copilot can generate FCFS code in C, Java, or Python with waiting-time and turnaround-time calculations. Always verify arrival-time sorting, tie-breaking, and average formulas before trusting the output.

Summarize this post with: