Selecting an Algorithm
The simulator supports five CPU scheduling algorithms, each with distinct characteristics:FIFO (First In First Out)
Processes are executed in the order they arrive. Simple but can cause long waiting times for short processes.
SJF (Shortest Job First)
Executes the process with the shortest CPU burst first. Minimizes average waiting time but requires knowing burst times in advance.
Round Robin
Time-sharing algorithm that gives each process a fixed time quantum. Fair distribution but may have higher context switching overhead.
Priority Scheduling
Processes are executed based on priority values. Important processes get CPU time first, but low-priority processes may starve.
MLFQ (Multi-Level Feedback Queue)
Advanced algorithm with multiple priority queues and different quantum values per level. Processes can move between queues based on behavior.
How to Select
On the initial screen (pantallaInicio), click the button corresponding to your desired algorithm. The seleccionarAlgoritmo(tipo) function will:
- Set the global variable
algoritmoActualto your selection - Hide the start screen
- Show the input form screen
- Update the title to display your chosen algorithm name
Entering Process Data
After selecting an algorithm, you’ll configure the simulation parameters.Step 1: Specify Number of Processes
Enter Process Count
In the “Número de procesos” field, enter a positive integer (e.g., 3, 5, 10). This represents how many processes will compete for CPU time.
Step 2: Configure Algorithm-Specific Parameters
Depending on your chosen algorithm, additional fields will appear:- FIFO
- SJF
- Round Robin
- Priority
- MLFQ
No additional parameters needed. You’ll only enter:
- Llegada (Arrival time) for each process
- CPU (CPU burst time) for each process
Step 3: Fill Process Parameters
For each process, you’ll see a section labeled “Proceso 1”, “Proceso 2”, etc. Arrival Time (Llegada):- The time unit when the process arrives in the system
- Can be 0 for processes that start immediately
- Processes arriving later will join the ready queue when their arrival time is reached
- The total CPU time this process requires
- Must be a positive integer
- Represents how long the process needs to execute
- Numeric priority value
- Determines execution order
- Check algorithm implementation for whether lower or higher values have priority
Input fields use IDs like
llegada0, cpu0, prioridad0 for the first process, llegada1, cpu1, prioridad1 for the second, and so on. The simular(n) function collects these values using these IDs.Running a Simulation
Click the Simular Button
After entering all process data, click the “Simular” button at the bottom of the form. This triggers the
simular(n) function.Algorithm Execution
The system:
- Collects data from all input fields
- Executes the selected algorithm (calls
fifo(),sjf(),roundRobin(),prioridad(), ormlfq()) - Calculates metrics: start time, finish time, waiting time, turnaround time
- Generates a step-by-step timeline for visualization
Results Display
The results screen appears showing:
- A table with metrics for each process (in the
salidadiv) - Total execution time
- Visual simulation components (CPU box, ready queue, Gantt chart)
- Control buttons for animation
Control Buttons
The results screen provides four control buttons to manage the visualization:▶ Iniciar (Start)
Function:iniciarSimulacion()
- Begins the step-by-step animation
- Updates every 500 milliseconds (0.5 seconds)
- Advances through the
timelineGlobalarray - Calls
renderPaso()for each time unit
- CPU box updates to show the executing process (or “Idle”)
- Ready queue displays waiting processes with animated pulse effect
- Gantt chart adds a new block for each time unit
- Timeline auto-scrolls horizontally to show the latest block
The animation automatically stops when
pasoActual reaches the end of the timeline.⏸ Pausar (Pause)
Function:pausarSimulacion()
- Stops the animation at the current step
- Preserves the current state (doesn’t reset)
- Click “Iniciar” again to resume from the paused position
- Uses
clearInterval()to stop the animation timer
🔄 Reiniciar (Reset)
Function:reiniciarSimulacion()
- Resets
pasoActualto 0 - Clears all visual components:
- CPU box resets to ”-”
- Ready queue becomes empty
- Gantt chart clears all blocks
- Preserves the results table and calculated metrics
- Click “Iniciar” to watch the simulation from the beginning
⬅ Volver al inicio (Back to Start)
Function:volverInicio()
- Returns to the algorithm selection screen
- Clears all data:
- Timeline and step counter
- Visual components (CPU, queue, Gantt)
- Results table
- Input fields and values
- Hides results and form screens
- Use this to start a completely new simulation
Real-Time Visualization Features
As the simulation runs, observe these dynamic elements:CPU Box Updates
CPU Box Updates
The CPU box (
cpuBox) changes every 500ms:- ”-”: Initial state, no simulation started
- “Idle”: CPU is not executing any process (waiting for arrivals or queue is empty)
- “P1”, “P2”, “P3”, etc.: Shows which process is currently executing
Queue Animation
Queue Animation
The
colaBox shows processes in the ready queue:- Each process appears as a rounded gray box with padding
- Boxes have a pulse animation (
animate-pulseclass) - For FIFO and SJF: Simple array of process IDs
- For Round Robin: Processes cycle through as they use their quantum
- For MLFQ: Multiple queue levels can be visible (nested structure)
Gantt Chart Construction
Gantt Chart Construction
The
ganttLive timeline builds from left to right:- Each time unit adds one 8x8 pixel block
- Blocks are indigo-colored and rounded
- Display the executing process ID or ”-” for idle
- Hover over blocks for a scale effect (1.1x zoom)
- Container auto-scrolls to keep the latest block visible
- Horizontal scrollbar appears for long simulations
Timeline Generation
The simulator uses different timeline generation methods based on the algorithm: Basic Timeline (FIFO, SJF, Priority):generarTimelineBasico()creates a snapshot for each time unit- Determines which process is executing at time t
- Queue information is limited (not dynamically tracked)
generarTimelineRR()simulates the circular queue behavior- Tracks remaining CPU time for each process
- Processes are added to the queue as they arrive
- After using quantum, process goes to the back of the queue
- Accurately shows queue state at each time unit
generarTimelineMLFQ()manages multiple priority queues- New processes start in the highest priority queue (queue 0)
- Processes use quantum for their current level
- If not completed, process moves to the next lower priority queue
- Shows complex queue dynamics across multiple levels
Example Workflow
Here’s a complete example of running a Round Robin simulation:Start Animation
Click ”▶ Iniciar”. Watch as:
- P1 executes for 2 units (quantum)
- P2 enters queue at time 1
- P1 moves to back of queue
- P2 executes for 2 units
- P3 enters queue at time 2
- Processes continue cycling until all complete