Lesson 4 of 15

Round-Robin Scheduler

The Linux Scheduler

The Linux kernel scheduler decides which READY process gets to run next. The original scheduler (pre-2.6) used a simple round-robin approach: give each process one time slice, then move to the next.

Modern Linux uses CFS (Completely Fair Scheduler), but round-robin is still used for real-time processes and is the foundation all schedulers build on.

Round-Robin Algorithm

[P1, P2, P3] all READY
tick 0: run P1 → advance to P2
tick 1: run P2 → advance to P3
tick 2: run P3 → advance to P1
tick 3: run P1 → ...

Key rules:

  • Only schedule READY processes (skip WAITING or ZOMBIE)
  • If no process is ready, print "idle"
  • Maintain a cursor that advances after each scheduled process

Your Implementation

Write void schedule(PCB procs[], int n, int ticks) that simulates ticks time slices:

void schedule(PCB procs[], int n, int ticks) {
    int cur = 0;
    for (int t = 0; t < ticks; t++) {
        int found = 0;
        for (int i = 0; i < n; i++) {
            if (procs[cur].state == READY) {
                printf("tick %d: %s\n", t, procs[cur].name);
                cur = (cur + 1) % n;
                found = 1;
                break;
            }
            cur = (cur + 1) % n;
        }
        if (!found) printf("tick %d: idle\n", t);
    }
}

Your Task

Implement schedule that simulates round-robin scheduling over the given process array.

TCC compiler loading...
Loading...
Click "Run" to execute your code.