CPU Scheduling

What Is the Simplest CPU Scheduling Algorithm?

First come, first served is the simplest CPU scheduling algorithm. Here is how it works, a worked example, and why its long waits can hurt.

On this page
  1. The short answer
  2. How it works
  3. A worked example
  4. Why it is simple but can respond slowly
  5. Where it still fits
  6. Stepping up from first come, first served

The short answer

The simplest CPU scheduling algorithm is first come, first served, often shortened to FCFS. It is also called first in, first out, or FIFO. The scheduler runs processes in the order they arrive, and each one keeps the CPU until it finishes or has to wait for something.

How it works

The operating system keeps the ready processes in a queue. When the CPU is free, it takes the process at the front of the queue and runs it. A newly ready process joins the back of the queue. Nothing is reordered, and a running process is not interrupted to let another one run. That makes first come, first served non-preemptive.

It needs no estimate of job length and no priority numbers, so the logic is easy to write and to check. That is what makes it the simplest method.

A worked example

Suppose three processes all arrive at time 0. P1 needs 24 time units of CPU, while P2 and P3 need 3 time units each. The arrival order is P1, P2, P3.

| P1 (0-24) | P2 (24-27) | P3 (27-30) |
  • P1 starts at 0 and finishes at 24. Its waiting time is 0.
  • P2 starts at 24 and finishes at 27. Its waiting time is 24.
  • P3 starts at 27 and finishes at 30. Its waiting time is 27.

The average waiting time is (0 + 24 + 27) / 3 = 17 time units.

Now take the same three processes in the order P2, P3, P1:

| P2 (0-3) | P3 (3-6) | P1 (6-30) |

P2 waits 0, P3 waits 3, and P1 waits 6. The average is 3 time units. The work is identical, but the waits are much shorter, purely because of the order.

Why it is simple but can respond slowly

The weakness is the convoy effect. When one long process is at the front, every short process behind it waits, even though each would take only a moment. Interactive programs suffer most, because a person can wait a long time for a short action to begin. For that reason, first come, first served is usually not the whole answer for systems that need quick responses.

Where it still fits

First come, first served is easy to build and easy to reason about. It can suit simple batch work, where jobs are similar in size and nobody is waiting at a keyboard for a reply. It can also serve as one of the rules inside more complex schemes.

Stepping up from first come, first served

The usual next steps are to run shorter jobs first, or to give each process a fixed time slice so that no single process can hold the CPU for long. Both reduce the waiting of short jobs, and each brings costs of its own.

The complete guide to cpu scheduling

CPU Scheduling Algorithms Explained
Read the guide

Keep exploring

Guides from other topics

All topics →