Skip to content

Commit fc97709

Browse files
committed
init
1 parent 7678738 commit fc97709

23 files changed

+1011
-0
lines changed

Diff for: .VSCodeCounter/2023-10-29_00-40-12/details.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Details
2+
3+
Date : 2023-10-29 00:40:12
4+
5+
Directory e:\\Homework\\操作系统课设\\final\\src
6+
7+
Total : 14 files, 12152 codes, 196 comments, 2488 blanks, all 14836 lines
8+
9+
[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md)
10+
11+
## Files
12+
| filename | language | code | comment | blank | total |
13+
| :--- | :--- | ---: | ---: | ---: | ---: |
14+
| [README.md](/README.md) | Markdown | 0 | 0 | 1 | 1 |
15+
| [build/main/xref-main.html](/build/main/xref-main.html) | HTML | 11,693 | 0 | 2,306 | 13,999 |
16+
| [main.py](/main.py) | Python | 6 | 0 | 2 | 8 |
17+
| [operate_system/__init__.py](/operate_system/__init__.py) | Python | 0 | 0 | 1 | 1 |
18+
| [operate_system/__os.py](/operate_system/__os.py) | Python | 82 | 49 | 31 | 162 |
19+
| [operate_system/__pcb.py](/operate_system/__pcb.py) | Python | 64 | 33 | 15 | 112 |
20+
| [operate_system/algorithm/__init__.py](/operate_system/algorithm/__init__.py) | Python | 0 | 8 | 2 | 10 |
21+
| [operate_system/algorithm/fcfs.py](/operate_system/algorithm/fcfs.py) | Python | 12 | 7 | 8 | 27 |
22+
| [operate_system/algorithm/hrrn.py](/operate_system/algorithm/hrrn.py) | Python | 15 | 5 | 8 | 28 |
23+
| [operate_system/algorithm/inout.py](/operate_system/algorithm/inout.py) | Python | 18 | 7 | 9 | 34 |
24+
| [operate_system/algorithm/rr.py](/operate_system/algorithm/rr.py) | Python | 14 | 9 | 8 | 31 |
25+
| [operate_system/algorithm/sjf.py](/operate_system/algorithm/sjf.py) | Python | 13 | 6 | 8 | 27 |
26+
| [operate_system/ui.py](/operate_system/ui.py) | Python | 218 | 72 | 89 | 379 |
27+
| [requirements.txt](/requirements.txt) | pip requirements | 17 | 0 | 0 | 17 |
28+
29+
[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md)

Diff for: .VSCodeCounter/2023-10-29_00-40-12/diff-details.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Diff Details
2+
3+
Date : 2023-10-29 00:40:12
4+
5+
Directory e:\\Homework\\操作系统课设\\final\\src
6+
7+
Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines
8+
9+
[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details
10+
11+
## Files
12+
| filename | language | code | comment | blank | total |
13+
| :--- | :--- | ---: | ---: | ---: | ---: |
14+
15+
[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details

Diff for: .VSCodeCounter/2023-10-29_00-40-12/diff.csv

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"filename", "language", "", "comment", "blank", "total"
2+
"Total", "-", , 0, 0, 0

Diff for: .VSCodeCounter/2023-10-29_00-40-12/diff.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Diff Summary
2+
3+
Date : 2023-10-29 00:40:12
4+
5+
Directory e:\\Homework\\操作系统课设\\final\\src
6+
7+
Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines
8+
9+
[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md)
10+
11+
## Languages
12+
| language | files | code | comment | blank | total |
13+
| :--- | ---: | ---: | ---: | ---: | ---: |
14+
15+
## Directories
16+
| path | files | code | comment | blank | total |
17+
| :--- | ---: | ---: | ---: | ---: | ---: |
18+
19+
[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md)

Diff for: .VSCodeCounter/2023-10-29_00-40-12/diff.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Date : 2023-10-29 00:40:12
2+
Directory : e:\Homework\操作系统课设\final\src
3+
Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines
4+
5+
Languages
6+
+----------+------------+------------+------------+------------+------------+
7+
| language | files | code | comment | blank | total |
8+
+----------+------------+------------+------------+------------+------------+
9+
+----------+------------+------------+------------+------------+------------+
10+
11+
Directories
12+
+------+------------+------------+------------+------------+------------+
13+
| path | files | code | comment | blank | total |
14+
+------+------------+------------+------------+------------+------------+
15+
+------+------------+------------+------------+------------+------------+
16+
17+
Files
18+
+----------+----------+------------+------------+------------+------------+
19+
| filename | language | code | comment | blank | total |
20+
+----------+----------+------------+------------+------------+------------+
21+
| Total | | 0 | 0 | 0 | 0 |
22+
+----------+----------+------------+------------+------------+------------+

Diff for: .VSCodeCounter/2023-10-29_00-40-12/results.csv

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"filename", "language", "pip requirements", "Python", "Markdown", "HTML", "comment", "blank", "total"
2+
"e:\Homework\操作系统课设\final\src\README.md", "Markdown", 0, 0, 0, 0, 0, 1, 1
3+
"e:\Homework\操作系统课设\final\src\build\main\xref-main.html", "HTML", 0, 0, 0, 11693, 0, 2306, 13999
4+
"e:\Homework\操作系统课设\final\src\main.py", "Python", 0, 6, 0, 0, 0, 2, 8
5+
"e:\Homework\操作系统课设\final\src\operate_system\__init__.py", "Python", 0, 0, 0, 0, 0, 1, 1
6+
"e:\Homework\操作系统课设\final\src\operate_system\__os.py", "Python", 0, 82, 0, 0, 49, 31, 162
7+
"e:\Homework\操作系统课设\final\src\operate_system\__pcb.py", "Python", 0, 64, 0, 0, 33, 15, 112
8+
"e:\Homework\操作系统课设\final\src\operate_system\algorithm\__init__.py", "Python", 0, 0, 0, 0, 8, 2, 10
9+
"e:\Homework\操作系统课设\final\src\operate_system\algorithm\fcfs.py", "Python", 0, 12, 0, 0, 7, 8, 27
10+
"e:\Homework\操作系统课设\final\src\operate_system\algorithm\hrrn.py", "Python", 0, 15, 0, 0, 5, 8, 28
11+
"e:\Homework\操作系统课设\final\src\operate_system\algorithm\inout.py", "Python", 0, 18, 0, 0, 7, 9, 34
12+
"e:\Homework\操作系统课设\final\src\operate_system\algorithm\rr.py", "Python", 0, 14, 0, 0, 9, 8, 31
13+
"e:\Homework\操作系统课设\final\src\operate_system\algorithm\sjf.py", "Python", 0, 13, 0, 0, 6, 8, 27
14+
"e:\Homework\操作系统课设\final\src\operate_system\ui.py", "Python", 0, 218, 0, 0, 72, 89, 379
15+
"e:\Homework\操作系统课设\final\src\requirements.txt", "pip requirements", 17, 0, 0, 0, 0, 0, 17
16+
"Total", "-", 17, 442, 0, 11693, 196, 2488, 14836

Diff for: .VSCodeCounter/2023-10-29_00-40-12/results.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/requirements.txt":{"language":"pip requirements","code":17,"comment":0,"blank":0},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/__os.py":{"language":"Python","code":82,"comment":49,"blank":31},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/algorithm/__init__.py":{"language":"Python","code":0,"comment":8,"blank":2},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/main.py":{"language":"Python","code":6,"comment":0,"blank":2},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/ui.py":{"language":"Python","code":218,"comment":72,"blank":89},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/__pcb.py":{"language":"Python","code":64,"comment":33,"blank":15},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/__init__.py":{"language":"Python","code":0,"comment":0,"blank":1},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/README.md":{"language":"Markdown","code":0,"comment":0,"blank":1},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/algorithm/sjf.py":{"language":"Python","code":13,"comment":6,"blank":8},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/algorithm/inout.py":{"language":"Python","code":18,"comment":7,"blank":9},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/algorithm/hrrn.py":{"language":"Python","code":15,"comment":5,"blank":8},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/algorithm/rr.py":{"language":"Python","code":14,"comment":9,"blank":8},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/operate_system/algorithm/fcfs.py":{"language":"Python","code":12,"comment":7,"blank":8},"file:///e%3A/Homework/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AF%BE%E8%AE%BE/final/src/build/main/xref-main.html":{"language":"HTML","code":11693,"comment":0,"blank":2306}}

Diff for: .VSCodeCounter/2023-10-29_00-40-12/results.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Summary
2+
3+
Date : 2023-10-29 00:40:12
4+
5+
Directory e:\\Homework\\操作系统课设\\final\\src
6+
7+
Total : 14 files, 12152 codes, 196 comments, 2488 blanks, all 14836 lines
8+
9+
Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md)
10+
11+
## Languages
12+
| language | files | code | comment | blank | total |
13+
| :--- | ---: | ---: | ---: | ---: | ---: |
14+
| HTML | 1 | 11,693 | 0 | 2,306 | 13,999 |
15+
| Python | 11 | 442 | 196 | 181 | 819 |
16+
| pip requirements | 1 | 17 | 0 | 0 | 17 |
17+
| Markdown | 1 | 0 | 0 | 1 | 1 |
18+
19+
## Directories
20+
| path | files | code | comment | blank | total |
21+
| :--- | ---: | ---: | ---: | ---: | ---: |
22+
| . | 14 | 12,152 | 196 | 2,488 | 14,836 |
23+
| . (Files) | 3 | 23 | 0 | 3 | 26 |
24+
| build | 1 | 11,693 | 0 | 2,306 | 13,999 |
25+
| build\\main | 1 | 11,693 | 0 | 2,306 | 13,999 |
26+
| operate_system | 10 | 436 | 196 | 179 | 811 |
27+
| operate_system (Files) | 4 | 364 | 154 | 136 | 654 |
28+
| operate_system\\algorithm | 6 | 72 | 42 | 43 | 157 |
29+
30+
Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md)

Diff for: .VSCodeCounter/2023-10-29_00-40-12/results.txt

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Date : 2023-10-29 00:40:12
2+
Directory : e:\Homework\操作系统课设\final\src
3+
Total : 14 files, 12152 codes, 196 comments, 2488 blanks, all 14836 lines
4+
5+
Languages
6+
+------------------+------------+------------+------------+------------+------------+
7+
| language | files | code | comment | blank | total |
8+
+------------------+------------+------------+------------+------------+------------+
9+
| HTML | 1 | 11,693 | 0 | 2,306 | 13,999 |
10+
| Python | 11 | 442 | 196 | 181 | 819 |
11+
| pip requirements | 1 | 17 | 0 | 0 | 17 |
12+
| Markdown | 1 | 0 | 0 | 1 | 1 |
13+
+------------------+------------+------------+------------+------------+------------+
14+
15+
Directories
16+
+-------------------------------------------------------------------+------------+------------+------------+------------+------------+
17+
| path | files | code | comment | blank | total |
18+
+-------------------------------------------------------------------+------------+------------+------------+------------+------------+
19+
| . | 14 | 12,152 | 196 | 2,488 | 14,836 |
20+
| . (Files) | 3 | 23 | 0 | 3 | 26 |
21+
| build | 1 | 11,693 | 0 | 2,306 | 13,999 |
22+
| build\main | 1 | 11,693 | 0 | 2,306 | 13,999 |
23+
| operate_system | 10 | 436 | 196 | 179 | 811 |
24+
| operate_system (Files) | 4 | 364 | 154 | 136 | 654 |
25+
| operate_system\algorithm | 6 | 72 | 42 | 43 | 157 |
26+
+-------------------------------------------------------------------+------------+------------+------------+------------+------------+
27+
28+
Files
29+
+-------------------------------------------------------------------+------------------+------------+------------+------------+------------+
30+
| filename | language | code | comment | blank | total |
31+
+-------------------------------------------------------------------+------------------+------------+------------+------------+------------+
32+
| e:\Homework\操作系统课设\final\src\README.md | Markdown | 0 | 0 | 1 | 1 |
33+
| e:\Homework\操作系统课设\final\src\build\main\xref-main.html | HTML | 11,693 | 0 | 2,306 | 13,999 |
34+
| e:\Homework\操作系统课设\final\src\main.py | Python | 6 | 0 | 2 | 8 |
35+
| e:\Homework\操作系统课设\final\src\operate_system\__init__.py | Python | 0 | 0 | 1 | 1 |
36+
| e:\Homework\操作系统课设\final\src\operate_system\__os.py | Python | 82 | 49 | 31 | 162 |
37+
| e:\Homework\操作系统课设\final\src\operate_system\__pcb.py | Python | 64 | 33 | 15 | 112 |
38+
| e:\Homework\操作系统课设\final\src\operate_system\algorithm\__init__.py | Python | 0 | 8 | 2 | 10 |
39+
| e:\Homework\操作系统课设\final\src\operate_system\algorithm\fcfs.py | Python | 12 | 7 | 8 | 27 |
40+
| e:\Homework\操作系统课设\final\src\operate_system\algorithm\hrrn.py | Python | 15 | 5 | 8 | 28 |
41+
| e:\Homework\操作系统课设\final\src\operate_system\algorithm\inout.py | Python | 18 | 7 | 9 | 34 |
42+
| e:\Homework\操作系统课设\final\src\operate_system\algorithm\rr.py | Python | 14 | 9 | 8 | 31 |
43+
| e:\Homework\操作系统课设\final\src\operate_system\algorithm\sjf.py | Python | 13 | 6 | 8 | 27 |
44+
| e:\Homework\操作系统课设\final\src\operate_system\ui.py | Python | 218 | 72 | 89 | 379 |
45+
| e:\Homework\操作系统课设\final\src\requirements.txt | pip requirements | 17 | 0 | 0 | 17 |
46+
| Total | | 12,152 | 196 | 2,488 | 14,836 |
47+
+-------------------------------------------------------------------+------------------+------------+------------+------------+------------+

Diff for: ProcessSchedulingSimulator.exe

13.5 MB
Binary file not shown.

Diff for: README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 进程调度模拟器
2+
3+
## 快速开始
4+
直接至 Releases
5+
6+
## 支持算法
7+
- [x] FCFS
8+
- [x] RR
9+
- [x] SJF
10+
- [x] HRRN
11+
12+
## 拓展支持

Diff for: main.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from operate_system.ui import UI
2+
import sys
3+
4+
if __name__ == '__main__':
5+
6+
ui = UI()
7+
ui.open_window()
8+
sys.exit(0)

Diff for: operate_system/__init__.py

Whitespace-only changes.

Diff for: operate_system/__os.py

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
from operate_system.__pcb import PCB
2+
3+
from operate_system.algorithm.fcfs import FCFS
4+
from operate_system.algorithm.rr import RR
5+
from operate_system.algorithm.sjf import SJF
6+
from operate_system.algorithm.hrrn import HRRN
7+
from operate_system.algorithm.inout import IO
8+
9+
from copy import deepcopy
10+
from random import randint
11+
12+
# 最早到达时间
13+
MIN_ARRIVE_TIME = int(0)
14+
15+
# 最晚到达时间
16+
MAX_ARRIVE_TIME = int(20)
17+
18+
# 最小运行时间
19+
MIN_RUN_TIME = int(50)
20+
21+
# 最大运行时间
22+
MAX_RUN_TIME = int(100)
23+
24+
# 最小阻塞时间
25+
MIN_WAIT_TIME = int(3)
26+
27+
ALGORITHMS = [FCFS, RR, SJF, HRRN]
28+
29+
class PC(object):
30+
"""
31+
模拟PC类
32+
"""
33+
34+
pid: int = 0
35+
time: int = 0
36+
time_slices: int = 0
37+
pcb_list: list[PCB] = []
38+
ready_queue: list[PCB] = []
39+
wait_queue: list[PCB] = []
40+
finish = False
41+
# io = IO()
42+
# cpu = CPU()
43+
44+
def __init__(self, pcb_list: list[PCB], algorithm_num: int, time_slices: int) -> None:
45+
"""
46+
初始化
47+
"""
48+
self.pcb_list = deepcopy(pcb_list)
49+
# self.pcb_list = pcb_list
50+
self.pcb_list.sort(key=lambda pcb: pcb.arrive_time)
51+
self.algorithm = ALGORITHMS[algorithm_num]()
52+
self.time_slices = time_slices
53+
self.io = IO()
54+
55+
def is_finish(self) -> bool:
56+
"""
57+
判断是否完成
58+
"""
59+
return self.finish == True
60+
61+
def createPcb(num: int) -> list[PCB]:
62+
"""
63+
创建PCB\n
64+
num: PCB数量
65+
"""
66+
# 自定义PCB部分
67+
# if len(args):
68+
# for each in args:
69+
# arrive_time = each.arrive_time
70+
# run_time = each.arrive_time
71+
# io_time = each.io_time
72+
# wait_time = each.wait_time
73+
# self.pcb.append(PCB(arrive_time, run_time, io_time, wait_time))
74+
pcb_list = []
75+
76+
for i in range(num):
77+
arrive_time = randint(MIN_ARRIVE_TIME, MAX_ARRIVE_TIME)
78+
run_time = randint(MIN_RUN_TIME, MAX_RUN_TIME)
79+
wait_time = randint(MIN_WAIT_TIME, run_time-MIN_RUN_TIME+MIN_WAIT_TIME)
80+
io_time = randint(1,run_time-wait_time)
81+
pcb_list.append(PCB(arrive_time,run_time,io_time,wait_time))
82+
pcb_list[i]._wait_time = wait_time
83+
84+
return pcb_list
85+
86+
def reset(self) -> None:
87+
"""
88+
重置
89+
"""
90+
# TODO
91+
self.time = 0
92+
self.ready_queue.clear()
93+
self.wait_queue.clear()
94+
# self.finish = True
95+
self.pcb_list.clear()
96+
97+
def step(self) -> (int, int|None, list):
98+
"""
99+
单步执行
100+
"""
101+
run_time = self.time_slices
102+
103+
finish = len(self.pcb_list)
104+
105+
for pcb in self.pcb_list:
106+
107+
# 将刚到达的进程加入到就绪队列
108+
if (pcb.is_none and pcb.is_arrive(self.time)):
109+
pcb.ready(self.pid)
110+
self.pid += 1
111+
self.ready_queue.append(pcb)
112+
113+
# 调用io,进程进入阻塞队列
114+
if (pcb.io_time == pcb.ran_time and not pcb.is_wait):
115+
pcb.wait()
116+
self.wait_queue.append(pcb)
117+
self.ready_queue.remove(pcb)
118+
119+
# 更新周转时间
120+
if not pcb.is_finish:
121+
pcb.update_turnaround_time(self.time)
122+
if (pcb.run_time == pcb.ran_time):
123+
self.ready_queue.remove(pcb) if pcb.is_running or pcb.is_ready else None
124+
self.wait_queue.remove(pcb) if pcb.is_wait else None
125+
pcb.finish(self.time)
126+
else:
127+
finish -= 1
128+
129+
# 执行调度算法
130+
run_time = self.algorithm(self.time, self.time_slices, self.ready_queue)
131+
132+
# io操作
133+
self.io(run_time, self.wait_queue, self.ready_queue)
134+
135+
# 调试使用
136+
# print(f"[{self.time}]pcb_list:")
137+
# for each in self.pcb_list:
138+
# print(f"{each}")
139+
# print("\n")
140+
141+
142+
# 判断结束
143+
self.finish = False if finish else True
144+
145+
# 时间流逝
146+
self.time += run_time
147+
148+
return run_time
149+
150+
@property
151+
def average_turnaround_time(self):
152+
time = 0
153+
for each in self.pcb_list:
154+
time += each.turnaround_time
155+
return str(time/len(self.pcb_list))
156+
157+
@property
158+
def double_ztime(self):
159+
time = 0
160+
for each in self.pcb_list:
161+
time += each.turnaround_time/(each.run_time-each._wait_time)
162+
return "{:.2f}".format(time/len(self.pcb_list))

0 commit comments

Comments
 (0)