Rust

How OS Schedulers Work, Simulated as JoJo Stands

A tick-based OS-scheduler simulation whose in-memory processes are granted JoJo Stand abilities — time-stop, power amplification, precognition — as real scheduler policy modifiers.

jojo-stands banner
jojo-stands — Stand abilities as scheduler policies

The idea

A modern CPU can only run a handful of instructions at a time, yet a running computer juggles hundreds of processes. The part of the operating system that decides which ready process gets the CPU next, and for how long, is the scheduler. This project builds a small, tick-based scheduler in Rust and then dresses each scheduling policy up as a JoJo Stand, because the anime’s abilities map cleanly onto real scheduler moves: The World (time-stop) behaves like non-preemptible priority that freezes everyone else; Star Platinum (precision) behaves like deterministic FIFO order; and Crazy Diamond (restoration) behaves like checkpoint/rollback of a task’s saved state.

The goal is to make the mechanics of scheduling — the run queue, the time quantum, the context switch — observable. You start the simulation, watch processes take turns tick by tick, and see exactly when and why the scheduler hands the CPU from one process to another.

Honest caveat: the JoJo mapping is a teaching metaphor, not a one-to-one correspondence — real Stands do not model any specific algorithm, and the simulator is an in-memory model, not a kernel. No real OS processes or threads are scheduled; “processes” are plain structs and the clock is a tick counter.

Scheduling in one page

Every process the scheduler knows about sits in one of a few states. A ready process wants the CPU and is waiting in the run queue; a running process currently owns the CPU; a blocked process is waiting on something (I/O, a timer) and is not eligible to run. The scheduler’s job is to move processes between these states and pick the next runner whenever the CPU comes free.

To keep any single process from monopolising the CPU, the scheduler hands out the CPU in bounded slices called a time quantum (or time slice). When a process’s quantum expires, the scheduler performs a context switch: it saves the outgoing process’s state (its registers and program counter, here just its saved fields), selects a new process, and restores that one’s state. Context switches are not free — a quantum that is too short wastes time switching, while one that is too long hurts responsiveness.

Which process is picked is the scheduling policy. Two classic policies bracket the design space. Round-robin gives every ready process an equal quantum in strict rotation: simple and fair, but it treats an urgent task the same as a background one. Priority scheduling always runs the highest-priority ready process; in its preemptive form, the arrival of a higher-priority process immediately interrupts whatever is running. Preemption improves responsiveness for important work but risks starvation, where low-priority processes never get a turn.

How this project demonstrates it

  • Each process is an in-memory struct holding a priority, a remaining work count, a saved state for rollback, and a Stand ability that acts as a policy modifier.
  • On every tick the scheduler consults the run queue, applies any active Stand modifiers, picks the next process, decrements its remaining work, and switches when the quantum ends — the same loop a real scheduler runs, minus the hardware.
  • Time-stop (The World) models non-preemptible priority: the Stand user runs uninterrupted for a fixed number of ticks regardless of what else is ready, then normal scheduling resumes.
  • Precision (Star Platinum) models deterministic FIFO within a priority band: the process runs to completion in arrival order and never yields early.
  • Restoration (Crazy Diamond) models checkpoint/rollback: the scheduler can reset a process to a previously saved in-memory state, illustrating how saved context is what makes preemption and recovery possible.
  • Because everything is in-memory and driven by a single tick loop, the run is deterministic and easy to inspect — the output log shows each policy decision as it happens.

JoJo Stands scheduler questions

What does an OS scheduler actually do?

It decides which ready process runs on the CPU next and for how long. It keeps a run queue of ready processes, grants each a time slice (quantum), and performs a context switch to swap one process out and another in when the quantum expires or a higher-priority task becomes ready.

What is the difference between round-robin and priority scheduling?

Round-robin gives every ready process an equal fixed quantum in rotation — fair, but blind to urgency. Priority scheduling always runs the highest-priority ready process, and in its preemptive form interrupts a running task the moment a higher-priority one arrives, at the risk of starving low-priority work.

Is this a real kernel scheduler?

No. It is an in-memory simulation: the processes are plain Rust structs in one program and the clock is a tick counter. No real OS threads or processes are scheduled, which is what lets it model policies safely without any kernel privileges.

Run it

git clone https://github.com/caelum0x/awesome-mad-projects.git
cd jojo-stands

cargo test
cargo run

# Tick 1: [The World] time-stop active — process DIO runs 5 ticks uninterrupted
# Tick 6: time-stop expired — normal scheduling resumes
# Tick 7: [Star Platinum] FIFO precision — Jotaro runs to completion