Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Priority-based CPU Scheduler

A Python implementation of a priority-based CPU scheduler using a time-slice model and process blocking intervals.


Features

  • Simulates a CPU scheduling algorithm with priority-based process handling.
  • Supports process preemption, blocking, and termination.
  • Outputs the simulation timeline, including process states.
  • Calculates average turnaround time (TAT) for all processes.
  • Handles process arrivals dynamically based on arrival times.
  • Configurable time_slice and block_duration values.
  • Debug mode (DEBUG flag) for detailed simulation logs.

Main Functionality

The scheduler manages three key queues:

  1. Arrival Queue

    • Stores processes waiting to enter the ready queue based on their arrival times.
  2. Ready Queue

    • Holds processes ready for execution, sorted by priority.
    • Processes are preempted at next quantum if a higher-priority process arrives.
  3. Blocked Queue

    • Contains processes temporarily halted due to reaching their block intervals.
    • These processes are moved back to the ready queue after their block duration ends.

Usage

The program requires an input file containing process definitions, and it accepts additional parameters for the time slice and block duration:

Input File Format

Each line in the file represents a process with the following space-separated fields:

  • Name: a sequence of non-blank characters representing the name of the process.
  • Priority: the priority level for the process, from 1 to 9. A higher number indicates a process should take precedence over lower-numbered priority processes.
  • Arrival Time: the time at which the process arrives in the system.
  • Total Time: the total amount of CPU time that will be used by the process.
  • Block Interval: the interval at which the process will block for I/O. When a process blocks, it is unavailable to run for the time specified by the command line argument block_duration.

Example Input File

# ProcessName Priority ArrivalTime TotalTime BlockInterval
A 1 0 10 3
B 2 2 5 2
C 3 4 7 4

Command-line Execution

python3 scheduler.py <input_file> <time_slice> <block_duration>

Example

python3 scheduler.py joblist2.txt 2 1
  • input_file: Path to the input file containing process details.
  • time_slice: the decimal integer length of the time slice for the Round-Robin scheduler.
  • block_duration: the decimal integer time length that a process is unavailable to run after it blocks.

Outputs

The scheduler produces a timeline of process events in the following format:

  • Start Time: When the event begins.
  • Process Name: Identifier for the process or "(IDLE)" if the CPU is idle.
  • Duration: Length of the event in time units.
  • Status:
    • T: Process terminated (completed all required CPU time).
    • B: Process blocked (reached block interval).
    • P: Process preempted by the time slice.
    • I: CPU idle.

Example Output

timeSlice: 2	blockDuration: 1
0	A	2	P
2	B	2	P
4	C	2	P
6	(IDLE)	1	I
...
Average Turnaround Time: 8.333

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages