Skip to content

Commit bf48414

Browse files
committed
finalized package and code formatting
1 parent 0115057 commit bf48414

File tree

5 files changed

+51
-33
lines changed

5 files changed

+51
-33
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea
2-
/__pycache__
2+
/__pycache__
3+
/venv

FCFS.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pygame, sys
2-
2+
import SJF
33
def get_font(size) : # Returns Press-Start-2P in the desired size
44
return pygame.font.SysFont('Comic Sans MS', size, pygame.font.Font.bold)
55
def FCFS():
@@ -12,13 +12,9 @@ def FCFS():
1212
pygame.display.set_caption("Menu")
1313
sc2 = flag = flag2 = False
1414
sc1 =True
15-
x = 300
15+
x = z = a= 300
1616
y = 320
17-
z = x
18-
c = 370
19-
a = x
20-
b = 370
21-
circle_list = []
17+
c = b= 370
2218
cir_rect = pygame.rect.Rect(500, 233, x, y)
2319
cir_rect2 = pygame.rect.Rect(500, 233, x, y)
2420
cir_rect3 = pygame.rect.Rect(500, 233, x, y)
@@ -30,7 +26,6 @@ def FCFS():
3026

3127
while True :
3228
if sc1 :
33-
PLAY_MOUSE_POS = pygame.mouse.get_pos()
3429
SCREEN.fill("black")
3530
pygame.draw.rect(SCREEN, "Blue", rex)
3631
pygame.draw.rect(SCREEN, "Blue", dex)
@@ -66,14 +61,12 @@ def FCFS():
6661
SCREEN.blit(PLAY_TEXT, PLAY_RECT)
6762
SCREEN.blit(Cir_TEXT, Cir_RECT)
6863
x = x + 1
69-
7064
cir_rect.update(0, 0, x, y)
7165
cir_rect2.update(0, 0, z, c)
7266
cir_rect3.update(0, 0, a, b)
7367
if a > 1200 :
7468
sc1 = False
7569
sc2 = True
76-
# dis = pygame.draw.circle(SCREEN, (212, 255, 0), (z, y), 20, 0)
7770
if flag2 :
7871
if circle.colliderect(pix) :
7972
b = b + 1
@@ -89,13 +82,13 @@ def FCFS():
8982
flag = True
9083
val1=0
9184
if sc2 :
92-
# SJF()
93-
sys.exit()
85+
SJF.SJF()
9486

9587
for event in pygame.event.get() :
9688
if event.type == pygame.QUIT :
9789
pygame.quit()
9890
sys.exit()
9991
if event.type == pygame.KEYDOWN :
10092
pygame.display.flip()
101-
pygame.display.update()
93+
pygame.display.update()
94+
FCFS()

README.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,75 @@
11
# CPU Scheduling Simulation
2+
3+
CPU scheduling is used to determine which process or task must be done **first** when many
4+
process are waiting to be completed. In this project I have created a simulation of these three algorithms to understand them more easier.
5+
26
CPU use may algorithms such as
7+
38
+ First Come First Served(FCFS)
49
+ Shortest Job First(SJF)
510
+ Round robin
611

7-
These are used to schedule which process or task must be done **first** when many
8-
process are waiting. In this project I have created a simulation of these three algorithms to understand them more easier.
9-
12+
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).
13+
These algorithms are designed to reduce waiting time and ensure that the CPU is continuously executing processes without being idle.
1014
## FCFS
1115

12-
The fisrt process which come will be processed by the CPU before processing the next process.
16+
The first process which come will be processed by the CPU before processing the next process.
1317

1418
## SJF
1519

1620
The process which have least time of execution will be processed first.
1721

1822
## Round Robin
1923

20-
The process is processed in multiple steps hence giving a equal chance to all processes
24+
The process is processed in multiple steps hence giving an equal chance to all processes. This is the **most efficient** algorithm for cpu scheduling
2125

2226
# Install with pip
23-
You can easily install this using pip,
27+
You can easily install the simulations of these three algorithms using pip. The name of the package is **CpuSchedulingSimulation**
28+
and the module used is **Cpu_scheduling_algorithms**. You can find the documentation [here](https://pypi.org/project/CpuSchedulingSimulation/#description)
29+
2430
```
25-
pip install Cpu-scheduling-simulation
31+
pip install CpuSchedulingSimulation
2632
```
33+
34+
> Note: This will also install pygame(version 2.1.2)
35+
2736
## Examples
2837

29-
Then just import the package and run the functions named as algorithms to see the simulation in action
38+
Then just import the package and run the functions named as algorithms to see the simulation in action.
3039
```python
31-
import CpuSchedulingSimulation as css
40+
import Cpu_scheduling_algorithms as css
3241
css.FCFS()
42+
```
43+
```python
3344
css.SJF()
45+
```
46+
```python
3447
css.Round_Robin()
3548
```
3649

3750

38-
# Packages used
51+
# Cloning the repo
52+
Use the following command to clone the repo to your local system.
53+
54+
```commandline
55+
git clone https://github.com/harisankar01/CPU-Scheduling-Simulation.git
56+
```
57+
Then go into the folder to execute the functions.
58+
```commandline
59+
cd CPU-Scheduling-Simulation
60+
```
61+
### Packages used
3962
**Pygame** a popular game library in pyton is used in this project to create simulation of the scheduling process
4063

4164
```
4265
pip install pygame
4366
```
44-
You can also clone the repository and run the command to see the simulation in action
67+
68+
Then finally run the main file which is `FCFS.py` and understand CPU scheduling easily.
69+
4570
```commandline
4671
python3 FCFS.py
4772
```
4873

49-
> Note: These simultaion can be used to understand CPU scheduling effectively, if you have basic knowledge of
74+
> Note: These simulations can be used to understand CPU scheduling effectively, if you have basic knowledge of
5075
> CPU scheduling algorithms

RoundRobin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ def Round_Robin():
1212
x=140
1313
y=320
1414
a=x-40
15-
b=y+50
15+
b= d=y+50
1616
c=x-80
17-
d=y+50
18-
cir_rect = pygame.rect.Rect(500, 233, x, y)
17+
cir_rect = pygame.rect.Rect(500, 233, x,y)
1918
cir_rect2 = pygame.rect.Rect(50, 23, a,b)
2019
cir_rect3 = pygame.rect.Rect(50, 23, c,d)
2120
rec_list = []
@@ -83,7 +82,7 @@ def Round_Robin():
8382
rr="0"
8483
if cir.collidepoint(1085,316):
8584
firstp="0"
86-
print(cir.x,cir.y)
85+
print(cir.x ,cir.y)
8786
a=a+0.6
8887
c=c+0.6
8988
cir_rect2.update(0,0,a,b)

SJF.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pygame, sys
2-
2+
import RoundRobin
33
def get_font(size) :
44
return pygame.font.SysFont('Comic Sans MS', size, pygame.font.Font.bold)
55

@@ -75,8 +75,8 @@ def SJF() :
7575
f = f - 13
7676
if e > 1200 :
7777
sc3 = True
78-
# Round_Robin()
79-
sys.exit()
78+
RoundRobin.Round_Robin()
79+
8080
Cir_TEXT = get_font(18).render(str(val1), True, "Red")
8181
Cir_RECT = Cir_TEXT.get_rect(center=cir_rect.size)
8282
SCREEN.blit(Cir_TEXT, Cir_RECT)

0 commit comments

Comments
 (0)