A command-line process scheduler simulator built in Java. This project simulates the behavior of an operating system's scheduler, handling processes with different scheduling policies on single-core and dual-core CPU configurations.
This program demonstrates fundamental concepts of operating systems, including process generation, scheduling, and execution. It is designed to run from the command line, taking user-defined parameters to configure the simulation, such as the scheduling policy, process execution times, and CPU configuration.
- Process Generation: A
Generadorthread creates new processes of different types (Arithmetic, I/O, Conditional, Loop) at random intervals. - Process Scheduling: A
Procesadorthread consumes and "executes" processes based on a selected scheduling policy. - Scheduling Policies Implemented:
FCFS: First-Come, First-ServedLCFS: Last-Come, First-ServedRR: Round-Robin (with a user-defined quantum)PP: Priority Policy (based on process type)
- CPU Configuration: The simulation can run in a single-processor or a dual-processor (
-dual) mode.
This project is composed of a core framework and a custom implementation that builds upon it.
The foundational classes, including the process definitions and the policy data structures, were provided as part of a university project.
- Author: Ing. Andrea Quan
- Core Components:
scheduler/processing/*: Classes defining different process types (ArithmeticProcess,InputOutputProcess, etc.).scheduler/scheduling/policies/*: Data structures and base logic for each scheduling policy (FirstComeFirstServed,RoundRobin, etc.).
My contribution was to build the simulation engine that uses the framework to bring the scheduler to life.
- Author: Jorge Cuevas
- Core Components:
ProcessScheduler.java: The main class. Parses command-line arguments, initializes the simulation, and prints final statistics.scheduler/Generador.java: A thread responsible for creating and queueing new processes according to the selected policy.scheduler/Procesador.java: A thread that simulates the CPU, dequeuing and processing tasks based on the scheduling policy and CPU configuration (single/dual core).
You will need a Java Development Kit (JDK) installed.
Open a terminal in the root directory of the project and run the following command. This will compile all .java files from the src folder and place the output .class files in a new bin folder.
javac -d bin src/**/*.javaNote: The wildcard ** works in modern shells like PowerShell or Bash. If you use an older command prompt, you might need to list the source files manually.
Use the java command from the root directory to run the program. The behavior of the simulation is controlled entirely through command-line arguments.
Once the simulation is running, press q and then Enter to stop it and view the final statistics.
The command structure is as follows:
java -cp bin ProcessScheduler [cpu_mode] [policy] [time_range] [arith_t] [io_t] [cond_t] [loop_t] [quantum_t]
Let's break down each part:
| Argument | Description | Example | Why it's important |
|---|---|---|---|
[cpu_mode] |
(Optional) Specifies if the CPU is dual-core. If omitted, it defaults to single-core. | -dual |
Tests the scheduler's performance with parallel processing. |
[policy] |
Required. The scheduling algorithm to use. | -fcfs, -rr |
This is the core of the simulation, defining how processes are chosen from the queue. |
[time_range] |
Required. The random interval (in seconds) at which new processes are created. A smaller range means faster generation. | 0.1-0.5 |
Controls the "load" on the system. A high load (fast generation) tests how well the scheduler handles a busy queue. |
[arith_t] |
Required. The execution time (in seconds) for an Arithmetic process. |
0.2 |
Defines how long the simulated CPU is "busy" with this type of task. |
[io_t] |
Required. The execution time (in seconds) for an InputOutput process. |
0.4 |
|
[cond_t] |
Required. The execution time (in seconds) for a Conditional process. |
0.1 |
|
[loop_t] |
Required. The execution time (in seconds) for a Loop process. |
0.3 |
|
[quantum_t] |
Required only for -rr policy. The maximum time slice (in seconds) a process can run before being interrupted. |
0.1 |
This is the key parameter for Round-Robin, demonstrating preemption. It must be smaller than the process execution times to see the effect. |
Here are some examples demonstrating the different scheduling policies in action.
Goal: To see how Round-Robin preempts a long-running process. We set the process execution time to 0.5s and the quantum to 0.2s.
Command:
java -cp bin ProcessScheduler -rr 0.5-1.0 0.5 0.5 0.5 0.5 0.2What Happens: A process like Numero: 1 needs 0.5s to run. The scheduler gives it 0.2s, stops it, puts it at the back of the queue, and attends to the next process. You will see Numero: 1 being processed multiple times, with its remaining time decreasing until it's finished.
Sample Output:
...
~~~Procesador Ejecutandose~~~
Procesador 1 esta atendiendo a: Numero: 1 Tiempo de atencion: 500 tipo: IO
...
~~~Procesador Ejecutandose~~~
Procesador 1 esta atendiendo a: Numero: 1 Tiempo de atencion: 300 tipo: IO
...
~~~Procesador Ejecutandose~~~
Procesador 1 esta atendiendo a: Numero: 1 Tiempo de atencion: 100 tipo: IO
...
q
La cantidad de procesos que se atendieron fue de: 56
La cantidad de procesos que quedaron sin atencion fue de: 14
El tiempo promedio de atencion por proceso es de: 500
Politica utilizada: Round-Robin
Goal: To demonstrate parallel processing. We use a fast generation time (0.2-0.5) to ensure the queue always has work for both CPUs.
Command:
java -cp bin ProcessScheduler -dual -fcfs 0.2-0.5 0.4 0.4 0.4 0.4What Happens: You will see "Procesador 1" and "Procesador 2" picking up different processes (Numero: 1 and Numero: 2) from the queue and working on them simultaneously. This significantly increases the system's throughput.
Sample Output:
~~~Procesador Ejecutandose~~~
Procesador 1 esta atendiendo a: Numero: 1 Tiempo de atencion: 400 tipo: C
Lista: [Numero: 2 Tiempo de atencion: 400 tipo: L]
La cantidad de procesos que ya se atendieron es de: 1
Procesador 2 esta atendiendo a: Numero: 2 Tiempo de atencion: 400 tipo: L
Lista: []
La cantidad de procesos que ya se atendieron es de: 2
La politica que se esta utilizando es: fcfs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Goal: To ensure the program is robust and provides user-friendly feedback on incorrect input.
Command:
java -cp bin ProcessScheduler -fcfsWhat Happens: The program detects that the required time arguments are missing and, instead of crashing with a Java exception, it prints helpful error messages and exits gracefully.
Output:
Por favor ingrese valores numericos para los tiempos.
Por favor ingrese argumentos en la linea de comandos.