Skip to content

Commit

Permalink
finalized package and code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
harisankar01 committed May 22, 2022
1 parent 0115057 commit bf48414
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.idea
/__pycache__
/__pycache__
/venv
19 changes: 6 additions & 13 deletions FCFS.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -89,13 +82,13 @@ def FCFS():
flag = True
val1=0
if sc2 :
# SJF()
sys.exit()
SJF.SJF()

for event in pygame.event.get() :
if event.type == pygame.QUIT :
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN :
pygame.display.flip()
pygame.display.update()
pygame.display.update()
FCFS()
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,75 @@
# 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

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
7 changes: 3 additions & 4 deletions RoundRobin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions SJF.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bf48414

Please sign in to comment.