Skip to content

About

A CPU simulating program made in JavaScript for Sister Jane's class assignment.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU Simulator

License: MIT

A browser simulator for COM 310 Operating Systems. It shows how one CPU schedules jobs: a job arrives, waits in the ready queue, runs for a clock tick, and finishes when its bursts are gone.

Live site: https://jaredscar.github.io/CPU-Simulator/

What you see

Before a run, the page explains the four stages of a job and the scheduler you picked. Changing the algorithm rewrites that lesson.

The simulator before a run. The lesson explains First Come, First Served, and the job pool, ready queue, and Gantt chart are empty.

During a run, the highlighted row is the job on the CPU. That same color is used in the ready queue and the Gantt chart. Each Gantt block is one clock tick, and the number under it is the clock. A gray block means the CPU was idle.

Round Robin at clock 5. Job 1 is on the CPU, jobs 2, 0, 3, and 4 are waiting, and the Gantt chart shows idle time followed by jobs 0 and 1.

A Round Robin run. The clock, ready queue, and Gantt chart advance one tick at a time.

The Gantt chart filling in. Gray blocks are idle ticks. Colored blocks are the job that owned the CPU, labeled with the clock time.

Run it locally

From this folder:

python -m http.server 8080

Open http://127.0.0.1:8080/

  • Simulate plays one clock tick per second.
  • Next Step holds the clock so you can read the decision.
  • Stop pauses a running simulation.
  • Finish runs the rest of the ticks immediately.
  • Quantum is the Round Robin time slice. The other algorithms ignore it.

How to read a tick

  1. A job cannot run before its arrival time.
  2. After it arrives, it waits in the ready queue. That time is its wait time. The front of the line is on the left.
  3. The scheduler picks one job. The CPU uses up one burst. Utilization is 100% while a job is running, and 0% on an idle tick.
  4. When no bursts remain, the job is finished. Turnaround is the time from arrival until then.

Waiting and turnaround averages are the usual way to compare schedulers on the same jobs. Lower is better for both.

Algorithms

First Come, First Served

The CPU runs the job that has been waiting the longest. Once a job starts, it keeps the CPU until every burst is done.

Shortest Job First

When the CPU is free, it picks the arrived job with the smallest total burst. A job that has started is not interrupted. This needs the burst length ahead of time, which a real interactive system usually does not know.

Shortest Remaining Time First

Like Shortest Job First, but preemptive. If a new job has less time remaining than the job on the CPU, the CPU switches immediately.

Round Robin

Every job gets the CPU for a fixed quantum, then moves to the back of the ready queue. A quantum of 1 switches almost every tick. A larger quantum looks closer to First Come, First Served.

Priority, non-preemptive

The ready queue is ordered by priority. A higher number is more important. The job on the CPU is not interrupted.

Priority, preemptive

The CPU always runs the highest-priority arrived job. If a more important job arrives, it takes the CPU immediately.

Assumptions

  1. A higher priority number is more important for both priority algorithms.
  2. Wait time is time spent in the ready queue, not time on the CPU.
  3. Turnaround time is the time from arrival until the job is fully done.
  4. Burst times range from 1 to 10 time units.
  5. Priority levels range from 0 to 100.
  6. The simulator schedules one CPU.

About

A CPU simulating program made in JavaScript for Sister Jane's class assignment.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages