0
0
Operating-systemsConceptBeginner · 3 min read

FCFS Scheduling: What It Is and How It Works

FCFS scheduling stands for First-Come, First-Served scheduling, a method where the CPU executes processes in the exact order they arrive. It is simple and easy to implement but can cause delays if a long process arrives first.
⚙️

How It Works

Imagine a line at a grocery store checkout. The cashier serves customers one by one in the order they arrive. FCFS scheduling works the same way for computer processes waiting to use the CPU.

When a process arrives, it joins the end of the queue. The CPU picks the first process in the queue and runs it until it finishes. Only then does it move to the next process. This means no process can jump ahead, ensuring fairness based on arrival time.

However, if a long process is first, shorter processes behind it must wait, which can cause delays known as the "convoy effect." Despite this, FCFS is easy to understand and implement.

💻

Example

This example shows how FCFS scheduling handles processes with different arrival and burst times.

python
processes = [
    {"id": "P1", "arrival": 0, "burst": 4},
    {"id": "P2", "arrival": 1, "burst": 3},
    {"id": "P3", "arrival": 2, "burst": 1}
]

current_time = 0
for p in processes:
    if current_time < p["arrival"]:
        current_time = p["arrival"]
    start_time = current_time
    finish_time = start_time + p["burst"]
    print(f"{p['id']} starts at {start_time} and finishes at {finish_time}")
    current_time = finish_time
Output
P1 starts at 0 and finishes at 4 P2 starts at 4 and finishes at 7 P3 starts at 7 and finishes at 8
🎯

When to Use

FCFS scheduling is best when simplicity is important and process arrival times are fairly predictable. It works well in batch systems where tasks are processed in order without interruption.

It is not ideal for time-sensitive tasks because long processes can delay others. Use FCFS when fairness by arrival time is more important than response speed.

Real-world examples include print queues or simple task scheduling where tasks are handled one after another without priority.

Key Points

  • FCFS schedules processes in the order they arrive.
  • It is simple and easy to implement.
  • Long processes can delay shorter ones (convoy effect).
  • Best for non-interactive, batch processing systems.
  • Does not prioritize processes based on importance or length.

Key Takeaways

FCFS scheduling runs processes in the order they arrive without interruption.
It is simple but can cause delays if a long process comes first.
Best suited for batch systems where fairness by arrival time matters.
Not ideal for interactive or time-sensitive tasks.
Easy to understand and implement for basic scheduling needs.