/CPU-Scheduling

Primary LanguageJavaApache License 2.0Apache-2.0

CPUScheduling

This Java program simulates different schedulers. It provides simulations for the following schedulers:

  1. Preemptive Shortest-Job First (SJF) Scheduling with context switching.
  2. Round Robin (RR) with context switching.
  3. Preemptive Priority Scheduling with the solution to the starvation problem.
  4. AG Scheduling:
    • Each process is provided with a static time to execute called quantum.
    • Once a process is executed for the given time period, it is treated as FCFS (First-Come, First-Served) until it finishes ceil(52%) of its quantum time. Then it is converted to non-preemptive Priority until it finishes the next ceil(52%) of its quantum time. After that, it is converted to preemptive Shortest-Job First (SJF).
    • There are 3 scenarios for the running process:
      1. The running process used all its quantum time and still has more job to do. In this case, the process is added to the end of the queue, and its quantum time is increased by two.
      2. The running process was executed as non-preemptive Priority and did not use all its quantum time because another process was converted from ready to running. In this case, the process is added to the end of the queue, and its quantum time is increased by ceil(the remaining quantum time/2).
      3. The running process was executed as preemptive Shortest-Job First (SJF) and did not use all its quantum time because another process was converted from ready to running. In this case, the process is added to the end of the queue, and its quantum time is increased by the remaining quantum time.
      4. The running process did not use all of its quantum time because it no longer needs that time and the job was completed. In this case, the process's quantum time is set to zero.

Program Input

The program expects the following input:

  1. Number of processes
  2. Round robin time quantum
  3. Context switching

For each process, the following parameters are required:

  1. Process Name
  2. Process Arrival Time
  3. Process Burst Time
  4. Process Priority

Program Output

For each scheduler, the program outputs the following:

  1. Processes execution order
  2. Waiting time for each process
  3. Turnaround time for each process
  4. Average waiting time
  5. Average turnaround time
  6. All history updates of quantum time for each process (AG Scheduling)