diff --git a/.gitignore b/.gitignore index d67c89a..bb80269 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea -/__pycache__ \ No newline at end of file +/__pycache__ +/venv \ No newline at end of file diff --git a/FCFS.py b/FCFS.py index 113f70f..ff2f7c6 100644 --- a/FCFS.py +++ b/FCFS.py @@ -1,5 +1,5 @@ import pygame, sys - +import SJF def get_font(size) : # Returns Press-Start-2P in the desired size return pygame.font.SysFont('Comic Sans MS', size, pygame.font.Font.bold) def FCFS(): @@ -12,13 +12,9 @@ def FCFS(): pygame.display.set_caption("Menu") sc2 = flag = flag2 = False sc1 =True - x = 300 + x = z = a= 300 y = 320 - z = x - c = 370 - a = x - b = 370 - circle_list = [] + c = b= 370 cir_rect = pygame.rect.Rect(500, 233, x, y) cir_rect2 = pygame.rect.Rect(500, 233, x, y) cir_rect3 = pygame.rect.Rect(500, 233, x, y) @@ -30,7 +26,6 @@ def FCFS(): while True : if sc1 : - PLAY_MOUSE_POS = pygame.mouse.get_pos() SCREEN.fill("black") pygame.draw.rect(SCREEN, "Blue", rex) pygame.draw.rect(SCREEN, "Blue", dex) @@ -66,14 +61,12 @@ def FCFS(): SCREEN.blit(PLAY_TEXT, PLAY_RECT) SCREEN.blit(Cir_TEXT, Cir_RECT) x = x + 1 - cir_rect.update(0, 0, x, y) cir_rect2.update(0, 0, z, c) cir_rect3.update(0, 0, a, b) if a > 1200 : sc1 = False sc2 = True - # dis = pygame.draw.circle(SCREEN, (212, 255, 0), (z, y), 20, 0) if flag2 : if circle.colliderect(pix) : b = b + 1 @@ -89,8 +82,7 @@ def FCFS(): flag = True val1=0 if sc2 : - # SJF() - sys.exit() + SJF.SJF() for event in pygame.event.get() : if event.type == pygame.QUIT : @@ -98,4 +90,5 @@ def FCFS(): sys.exit() if event.type == pygame.KEYDOWN : pygame.display.flip() - pygame.display.update() \ No newline at end of file + pygame.display.update() +FCFS() \ No newline at end of file diff --git a/README.md b/README.md index 5ce3ae4..0003285 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ # CPU Scheduling Simulation + + CPU scheduling is used to determine which process or task must be done **first** when many +process are waiting to be completed. In this project I have created a simulation of these three algorithms to understand them more easier. + CPU use may algorithms such as + + First Come First Served(FCFS) + Shortest Job First(SJF) + Round robin - These are used to schedule which process or task must be done **first** when many -process are waiting. In this project I have created a simulation of these three algorithms to understand them more easier. - + Basically a process have a fixed execution time(time required to complete the process), waiting time(time the process has to wait to be processed). +These algorithms are designed to reduce waiting time and ensure that the CPU is continuously executing processes without being idle. ## FCFS -The fisrt process which come will be processed by the CPU before processing the next process. +The first process which come will be processed by the CPU before processing the next process. ## SJF @@ -17,34 +21,55 @@ The process which have least time of execution will be processed first. ## Round Robin -The process is processed in multiple steps hence giving a equal chance to all processes +The process is processed in multiple steps hence giving an equal chance to all processes. This is the **most efficient** algorithm for cpu scheduling # Install with pip - You can easily install this using pip, + You can easily install the simulations of these three algorithms using pip. The name of the package is **CpuSchedulingSimulation** + and the module used is **Cpu_scheduling_algorithms**. You can find the documentation [here](https://pypi.org/project/CpuSchedulingSimulation/#description) + ``` -pip install Cpu-scheduling-simulation +pip install CpuSchedulingSimulation ``` + +> Note: This will also install pygame(version 2.1.2) + ## Examples -Then just import the package and run the functions named as algorithms to see the simulation in action +Then just import the package and run the functions named as algorithms to see the simulation in action. ```python -import CpuSchedulingSimulation as css +import Cpu_scheduling_algorithms as css css.FCFS() +``` +```python css.SJF() +``` +```python css.Round_Robin() ``` -# Packages used +# Cloning the repo +Use the following command to clone the repo to your local system. + +```commandline +git clone https://github.com/harisankar01/CPU-Scheduling-Simulation.git +``` +Then go into the folder to execute the functions. +```commandline +cd CPU-Scheduling-Simulation +``` +### Packages used **Pygame** a popular game library in pyton is used in this project to create simulation of the scheduling process ``` pip install pygame ``` -You can also clone the repository and run the command to see the simulation in action + +Then finally run the main file which is `FCFS.py` and understand CPU scheduling easily. + ```commandline python3 FCFS.py ``` -> Note: These simultaion can be used to understand CPU scheduling effectively, if you have basic knowledge of +> Note: These simulations can be used to understand CPU scheduling effectively, if you have basic knowledge of > CPU scheduling algorithms diff --git a/RoundRobin.py b/RoundRobin.py index e190c0d..33e7346 100644 --- a/RoundRobin.py +++ b/RoundRobin.py @@ -12,10 +12,9 @@ def Round_Robin(): x=140 y=320 a=x-40 - b=y+50 + b= d=y+50 c=x-80 - d=y+50 - cir_rect = pygame.rect.Rect(500, 233, x, y) + cir_rect = pygame.rect.Rect(500, 233, x,y) cir_rect2 = pygame.rect.Rect(50, 23, a,b) cir_rect3 = pygame.rect.Rect(50, 23, c,d) rec_list = [] @@ -83,7 +82,7 @@ def Round_Robin(): rr="0" if cir.collidepoint(1085,316): firstp="0" - print(cir.x,cir.y) + print(cir.x ,cir.y) a=a+0.6 c=c+0.6 cir_rect2.update(0,0,a,b) diff --git a/SJF.py b/SJF.py index 004440e..863455c 100644 --- a/SJF.py +++ b/SJF.py @@ -1,5 +1,5 @@ import pygame, sys - +import RoundRobin def get_font(size) : return pygame.font.SysFont('Comic Sans MS', size, pygame.font.Font.bold) @@ -75,8 +75,8 @@ def SJF() : f = f - 13 if e > 1200 : sc3 = True - # Round_Robin() - sys.exit() + RoundRobin.Round_Robin() + Cir_TEXT = get_font(18).render(str(val1), True, "Red") Cir_RECT = Cir_TEXT.get_rect(center=cir_rect.size) SCREEN.blit(Cir_TEXT, Cir_RECT)