A from-scratch C implementation of three classic CPU scheduling algorithms — FCFS, SJF (non-preemptive), and Round Robin — with a self-checking test harness (calculated vs. expected metrics) and a Dockerized build/run.
An operating-systems project that implements and validates the three foundational CPU scheduling policies in C. Each scheduler computes the standard performance metrics, and a dedicated test driver checks the calculated values against hand-derived expected values across multiple test cases — so correctness is demonstrated, not just asserted.
Algorithms
- FCFS — First Come First Served
- SJF — Shortest Job First (non-preemptive)
- Round Robin — time-sliced with a configurable quantum
Metrics computed for each
- Average Turnaround Time (completion − arrival)
- Average Waiting Time (turnaround − burst)
- Average Response Time (start − arrival)
- Correctness is tested, not claimed.
scheduler_test.cruns 8 test cases and asserts calculated metrics equal expected metrics for all three algorithms; a clean run printsALL TESTS PASSED. - Clean separation of interface (
scheduler.h), implementation (scheduler.c), and tests (scheduler_test.c). - Reproducible anywhere via Docker — no local toolchain required.
With Docker (no local compiler needed):
docker build -t cpu-scheduler .
docker run --rm cpu-schedulerLocally with gcc:
gcc scheduler.c scheduler_test.c -o scheduler_test
./scheduler_testEither way you'll see calculated-vs-expected metrics per test case:
==== Test Case 1 ====
FCFS: Calculated: Turnaround: 15.00, Waiting: 7.33, Response: 7.33
Expected: Turnaround: 15.00, Waiting: 7.33, Response: 7.33
RR (Quantum = 4): Calculated: Turnaround: 19.33, Waiting: 11.67, Response: 3.00
Expected: Turnaround: 19.33, Waiting: 11.67, Response: 3.00
>>> Test Case 1 PASSED.
...
ALL TESTS PASSED.
CPU-Scheduling-Algorithms/
├── scheduler.h # structs + scheduling function declarations
├── scheduler.c # FCFS, SJF, Round Robin implementations
├── scheduler_test.c # 8 test cases asserting calculated vs. expected metrics
└── Dockerfile # containerized build & run
Systems programming in C · operating-systems scheduling theory (FCFS / SJF / Round Robin) · turnaround / waiting / response-time analysis · test-driven validation with assertions · Docker containerization · clean header/implementation/test separation.
Author: Arya Kalantari · github.com/Aria-Kalantari