├── Debug
├── processAndResourceManage.write.1.tlog
├── PCB.obj
├── Tool.obj
├── main.obj
├── Shell.obj
├── vc100.idb
├── vc100.pdb
├── MyProcess.obj
├── Resource.obj
├── ResourceA.obj
├── ResourceB.obj
├── CL.read.1.tlog
├── CL.write.1.tlog
├── mt.read.1.tlog
├── mt.write.1.tlog
├── ProcessManage.obj
├── ResourceManage.obj
├── cl.command.1.tlog
├── link.read.1.tlog
├── link.write.1.tlog
├── mt.command.1.tlog
├── link.command.1.tlog
├── processAndResourceManage.lastbuildstate
├── processAndResourceManage.vcxprojResolveAssemblyReference.cache
├── processAndResourceManage.exe.intermediate.manifest
└── processAndResourceManage.log
├── PCB.h
├── Tool.h
├── PCB.cpp
├── Shell.cpp
├── Shell.h
├── Tool.cpp
├── MyProcess.h
├── Resource.h
├── system.png
├── ProcessManage.h
├── ResourceManage.h
├── ProcessManage.cpp
├── ResourceManage.cpp
├── ResourceA.cpp
├── ResourceB.cpp
├── ResourceB.h
├── processAndResourceManage.vcxproj.user
├── ResourceA.h
├── Resource.cpp
├── MyProcess.cpp
├── main.cpp
├── ClassDiagram1.cd
├── processAndResourceManage.vcxproj.filters
├── processAndResourceManage.vcxproj
└── README.md
/Debug/processAndResourceManage.write.1.tlog:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/PCB.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/PCB.h
--------------------------------------------------------------------------------
/Tool.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Tool.h
--------------------------------------------------------------------------------
/PCB.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/PCB.cpp
--------------------------------------------------------------------------------
/Shell.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Shell.cpp
--------------------------------------------------------------------------------
/Shell.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Shell.h
--------------------------------------------------------------------------------
/Tool.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Tool.cpp
--------------------------------------------------------------------------------
/MyProcess.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/MyProcess.h
--------------------------------------------------------------------------------
/Resource.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Resource.h
--------------------------------------------------------------------------------
/system.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/system.png
--------------------------------------------------------------------------------
/Debug/PCB.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/PCB.obj
--------------------------------------------------------------------------------
/Debug/Tool.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/Tool.obj
--------------------------------------------------------------------------------
/Debug/main.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/main.obj
--------------------------------------------------------------------------------
/Debug/Shell.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/Shell.obj
--------------------------------------------------------------------------------
/Debug/vc100.idb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/vc100.idb
--------------------------------------------------------------------------------
/Debug/vc100.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/vc100.pdb
--------------------------------------------------------------------------------
/ProcessManage.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/ProcessManage.h
--------------------------------------------------------------------------------
/ResourceManage.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/ResourceManage.h
--------------------------------------------------------------------------------
/Debug/MyProcess.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/MyProcess.obj
--------------------------------------------------------------------------------
/Debug/Resource.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/Resource.obj
--------------------------------------------------------------------------------
/Debug/ResourceA.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/ResourceA.obj
--------------------------------------------------------------------------------
/Debug/ResourceB.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/ResourceB.obj
--------------------------------------------------------------------------------
/ProcessManage.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/ProcessManage.cpp
--------------------------------------------------------------------------------
/ResourceManage.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/ResourceManage.cpp
--------------------------------------------------------------------------------
/Debug/CL.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/CL.read.1.tlog
--------------------------------------------------------------------------------
/Debug/CL.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/CL.write.1.tlog
--------------------------------------------------------------------------------
/Debug/mt.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/mt.read.1.tlog
--------------------------------------------------------------------------------
/Debug/mt.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/mt.write.1.tlog
--------------------------------------------------------------------------------
/Debug/ProcessManage.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/ProcessManage.obj
--------------------------------------------------------------------------------
/Debug/ResourceManage.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/ResourceManage.obj
--------------------------------------------------------------------------------
/Debug/cl.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/cl.command.1.tlog
--------------------------------------------------------------------------------
/Debug/link.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/link.read.1.tlog
--------------------------------------------------------------------------------
/Debug/link.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/link.write.1.tlog
--------------------------------------------------------------------------------
/Debug/mt.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/mt.command.1.tlog
--------------------------------------------------------------------------------
/Debug/link.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/link.command.1.tlog
--------------------------------------------------------------------------------
/Debug/processAndResourceManage.lastbuildstate:
--------------------------------------------------------------------------------
1 | #v4.0:v100
2 | Debug|Win32|D:\Coding\C++\processAndResourceManage\|
3 |
--------------------------------------------------------------------------------
/ResourceA.cpp:
--------------------------------------------------------------------------------
1 | #include "ResourceA.h"
2 |
3 |
4 | ResourceA::ResourceA(void)
5 | :Resource(10)
6 | {
7 | }
8 |
9 |
10 | ResourceA::~ResourceA(void)
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/ResourceB.cpp:
--------------------------------------------------------------------------------
1 | #include "ResourceB.h"
2 |
3 |
4 | ResourceB::ResourceB(void)
5 | :Resource(15)
6 | {
7 | }
8 |
9 |
10 | ResourceB::~ResourceB(void)
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/ResourceB.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "resource.h"
3 | class ResourceB :
4 | public Resource
5 | {
6 | public:
7 | ResourceB(void);
8 | ~ResourceB(void);
9 | };
10 |
11 |
--------------------------------------------------------------------------------
/processAndResourceManage.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/ResourceA.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "resource.h"
3 | class ResourceA :
4 | public Resource
5 | {
6 | public:
7 | ResourceA(void);
8 | ~ResourceA(void);
9 |
10 | };
11 |
12 |
--------------------------------------------------------------------------------
/Debug/processAndResourceManage.vcxprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZPWX/processAndResourceManage/HEAD/Debug/processAndResourceManage.vcxprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/Resource.cpp:
--------------------------------------------------------------------------------
1 | #include "Resource.h"
2 |
3 |
4 | Resource::Resource(const int& amount)
5 | :amount(amount)
6 | {
7 | }
8 |
9 |
10 | Resource::~Resource(void)
11 | {
12 | }
13 |
14 | int Resource::getAmount() {
15 | return amount;
16 | }
--------------------------------------------------------------------------------
/Debug/processAndResourceManage.exe.intermediate.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/MyProcess.cpp:
--------------------------------------------------------------------------------
1 | #include "MyProcess.h"
2 | #include "Tool.h"
3 |
4 |
5 | MyProcess::MyProcess(const std::string& theName, const int& thePriority, const int& resourceA,
6 | const int& resourceB)
7 | :name(theName),
8 | priority(thePriority),
9 | resourceA(resourceA),
10 | resourceB(resourceB)
11 | {
12 | }
13 |
14 | MyProcess::MyProcess(const std::string& theName, const int& thePriority)
15 | :name(theName),
16 | priority(thePriority),
17 | resourceA(Tool::resourceRandom()),
18 | resourceB(Tool::resourceRandom())
19 | {
20 | }
21 |
22 |
23 |
24 | MyProcess::~MyProcess(void)
25 | {
26 | }
27 |
28 | std::string MyProcess::getName() {
29 | return name;
30 | }
31 |
32 | void MyProcess::getResourceNeed(int& resourceA, int& resourceB) {
33 | resourceA = this->resourceA;
34 | resourceB = this->resourceB;
35 | }
36 |
37 | int MyProcess::getPriority() {
38 | return priority;
39 | }
40 |
41 | int MyProcess::getState() {
42 | return state;
43 | }
44 |
45 | bool MyProcess::setState(const int& state) {
46 | this->state = state;
47 | return true;
48 | }
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "Shell.h"
6 |
7 | int main() {
8 | Shell* shell = new Shell();
9 |
10 | std::vector instrucks;
11 |
12 | instrucks.push_back("cr firstProcess 2");
13 | instrucks.push_back("list_r");
14 | instrucks.push_back("cr secondProcess 1");
15 | instrucks.push_back("list_r");
16 | instrucks.push_back("list_p");
17 | instrucks.push_back("de firstProcess");
18 | instrucks.push_back("list_p");
19 | instrucks.push_back("list_r");
20 | instrucks.push_back("cr firstProcess 2");
21 | instrucks.push_back("cr secondProcess 1");
22 | instrucks.push_back("list_r");
23 | instrucks.push_back("list_p");
24 | instrucks.push_back("to");
25 | instrucks.push_back("list_r");
26 | instrucks.push_back("list_p");
27 | instrucks.push_back("cr P3 2");
28 | instrucks.push_back("cr P4 2");
29 | instrucks.push_back("list_r");
30 | instrucks.push_back("list_p");
31 | instrucks.push_back("rel");
32 | instrucks.push_back("list_r");
33 | instrucks.push_back("list_p");
34 | instrucks.push_back("cr P5 1");
35 | instrucks.push_back("cr P6 1");
36 | instrucks.push_back("list_r");
37 | instrucks.push_back("list_p");
38 | //instrucks.push_back("de secondProcess");
39 | //instrucks.push_back("list_p");
40 | //instrucks.push_back("cr thirdProcess 1");
41 | //instrucks.push_back("cr firstProcess 2");
42 | //instrucks.push_back("cr firstProcess 2");
43 |
44 | int index = 0;
45 | std::cout << ">>" << instrucks.at(index) << std::endl;
46 | while(shell->read(instrucks.at(index)) && index+1 < instrucks.size()) {
47 | ++index;
48 | std::cout << std::endl;
49 | std::cout << ">>" << instrucks.at(index) << std::endl;
50 | }
51 |
52 | system("pause");
53 | }
--------------------------------------------------------------------------------
/ClassDiagram1.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | QAAAAEAAQAQAACAAAAIAAAAAAAAEAAAEAAAEAAIAAAQ=
7 | MyProcess.h
8 |
9 |
10 |
11 |
12 |
13 | QAAIAAQAAQAAIAAAARAAAAABAAAYMAEAIQACAAIAIAU=
14 | PCB.h
15 |
16 |
17 |
18 |
19 |
20 | QAAAABIAIAAAAAAIMABAAECAAADAAAJiDACAAAACCAA=
21 | ProcessManage.h
22 |
23 |
24 |
25 |
26 |
27 | AAAAAAAAIAAAAAAIAAAAAAAAAAACgAAAAAAAAAAAAAA=
28 | Resource.h
29 |
30 |
31 |
32 |
33 |
34 | AAAAAAAAIAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
35 | ResourceA.h
36 |
37 |
38 |
39 |
40 |
41 | AAAAAAAAIAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAA=
42 | ResourceB.h
43 |
44 |
45 |
46 |
47 |
48 | AIAAEAAAAACABCAABAAAkAAAAAAAAAAAAAAAAAAAAAA=
49 | ResourceManage.h
50 |
51 |
52 |
53 |
54 |
55 | AAAAAAAAAIAAAAAAASAAAAAIAAAAAAAAAAAAAAAAAAA=
56 | Shell.h
57 |
58 |
59 |
60 |
61 |
62 | AAAAAACAAAAAAAAAAAAQAAAAABAgAAAAABAAAAAAAAA=
63 | Tool.h
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/processAndResourceManage.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | 源文件
20 |
21 |
22 | 源文件
23 |
24 |
25 | 源文件
26 |
27 |
28 | 源文件
29 |
30 |
31 | 源文件
32 |
33 |
34 | 源文件
35 |
36 |
37 | 源文件
38 |
39 |
40 | 源文件
41 |
42 |
43 | 源文件
44 |
45 |
46 | 源文件
47 |
48 |
49 |
50 |
51 | 头文件
52 |
53 |
54 | 头文件
55 |
56 |
57 | 头文件
58 |
59 |
60 | 头文件
61 |
62 |
63 | 头文件
64 |
65 |
66 | 头文件
67 |
68 |
69 | 头文件
70 |
71 |
72 | 头文件
73 |
74 |
75 | 头文件
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Debug/processAndResourceManage.log:
--------------------------------------------------------------------------------
1 | 生成启动时间为 5/9/2017 7:15:29 PM。
2 | 1>项目“D:\Coding\C++\processAndResourceManage\processAndResourceManage\processAndResourceManage.vcxproj”在节点 2 上(build 个目标)。
3 | 1>InitializeBuildStatus:
4 | 正在创建“Debug\processAndResourceManage.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
5 | ClCompile:
6 | C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt main.cpp
7 | main.cpp
8 | 1>d:\coding\c++\processandresourcemanage\processandresourcemanage\main.cpp(24): warning C4018: “<”: 有符号/无符号不匹配
9 | Link:
10 | C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"D:\Coding\C++\processAndResourceManage\Debug\processAndResourceManage.exe" /NOLOGO opencv_calib3d244d.lib opencv_imgproc244d.lib opencv_highgui244d.lib opencv_contrib244d.lib opencv_core244d.lib opencv_features2d244d.lib opencv_flann244d.lib opencv_gpu244d.lib opencv_legacy244d.lib opencv_ml244d.lib opencv_objdetect244d.lib opencv_ts244d.lib opencv_video244d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Debug\processAndResourceManage.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Coding\C++\processAndResourceManage\Debug\processAndResourceManage.pdb" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\Coding\C++\processAndResourceManage\Debug\processAndResourceManage.lib" /MACHINE:X86 Debug\main.obj
11 | Debug\MyProcess.obj
12 | Debug\PCB.obj
13 | Debug\ProcessManage.obj
14 | Debug\Resource.obj
15 | Debug\ResourceA.obj
16 | Debug\ResourceB.obj
17 | Debug\ResourceManage.obj
18 | Debug\Shell.obj
19 | Debug\Tool.obj
20 | LINK : 没有找到 D:\Coding\C++\processAndResourceManage\Debug\processAndResourceManage.exe 或上一个增量链接没有生成它;正在执行完全链接
21 | processAndResourceManage.vcxproj -> D:\Coding\C++\processAndResourceManage\Debug\processAndResourceManage.exe
22 | Manifest:
23 | C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /outputresource:"D:\Coding\C++\processAndResourceManage\Debug\processAndResourceManage.exe;#1" /manifest Debug\processAndResourceManage.exe.intermediate.manifest
24 | FinalizeBuildStatus:
25 | 正在删除文件“Debug\processAndResourceManage.unsuccessfulbuild”。
26 | 正在对“Debug\processAndResourceManage.lastbuildstate”执行 Touch 任务。
27 | 1>已完成生成项目“D:\Coding\C++\processAndResourceManage\processAndResourceManage\processAndResourceManage.vcxproj”(build 个目标)的操作。
28 |
29 | 生成成功。
30 |
31 | 已用时间 00:00:03.26
32 |
--------------------------------------------------------------------------------
/processAndResourceManage.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {617086EB-5B42-4384-9B7B-D980F11A65A4}
15 | processAndResourceManage
16 |
17 |
18 |
19 | Application
20 | true
21 | MultiByte
22 |
23 |
24 | Application
25 | false
26 | true
27 | MultiByte
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | Level3
43 | Disabled
44 |
45 |
46 | true
47 |
48 |
49 |
50 |
51 | Level3
52 | MaxSpeed
53 | true
54 | true
55 |
56 |
57 | true
58 | true
59 | true
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 进程与资源管理实验
2 | ****
3 | ## 一、实验原理
4 | 利用相应的操作系统的进程创建、删除和调度原理,通过编程语言来实现模拟一个操作系统的进程调度
5 |
6 | ## 二、实验目的
7 | 设计和实现进程与资源管理,并完成Test shell的编写,以建立系统的进程管理、调度、资源管理和分配的知识体系,从而加深对操作系统进程调度和资源管理功能的宏观理解和微观实现技术的掌握。
8 |
9 | ## 三、实验内容
10 | 在实验室提供的软硬件环境中,设计并实现一个基本的进程与资源管理器。该管理器能够完成进程的控制,如进程创建与撤销、进程的状态转换;能够基于优先级调度算法完成进程的调度,模拟时钟中断,在同优先级进程中采用时间片轮转调度算法进行调度;能够完成资源的分配与释放,并完成进程之间的同步。该管理器同时也能完成从用户终端或者指定文件读取用户命令,通过Test shell模块完成对用户命令的解释,将用户命令转化为对进程与资源控制的具体操作,并将执行结果输出到终端或指定文件中。
11 |
12 | ## 四、实验环境
13 | - 平台:Windows
14 | - 语言:C++
15 |
16 | ## 五、实验步骤
17 | ### 1.系统功能分析
18 | 系统应具备以下功能:
19 |
20 | - 驱动程序(shell)
21 | - 从终端或者测试文件读取命令
22 | - 将用户需求转换成调度内核函数(即调度进程和资源管理器)
23 | - 在终端或输出文件中显示结果:如当前运行的进程、错误信息等。
24 |
25 | - 进程
26 | - 进程的创建
27 | - 进程的切换
28 | - 进程的删除
29 | - 错误检测
30 | - 定时器中断
31 |
32 | - 资源管理
33 | - 资源的申请
34 | - 资源的释放
35 |
36 | ### 2. 总体架构设计
37 | 系统的总体架构图如下:
38 |
39 | 
40 |
41 | 图中最右边部分为进程与资源管理器,属于操作系统内核的功能。该管理器具有如下功能:完成进程创建、撤销和进程调度;完成多单元 (multi_unit)资源的管理;完成资源的申请和释放;完成错误检测和定时器中断功能。
42 |
43 | 图中间绿色部分为驱动程序 shell, 设计与实现 shell,该 shell将调度所设计的进程与资源管理器来完成测试。
44 |
45 | 图中最左端部分为:通过终端(如键盘输入)或者测试文件来给出相应的用户命令,以及模拟硬件引起的中断
46 |
47 | ### 3.具体模块设计
48 | 这里把系统分为三个模块,分别是进程模块、TEST Shell 模块和资源模块,具体的设计细节在下面会有说明,在其中类的说明中类成员没有括号,类方法有括号
49 |
50 | 系统的大体运行流程:最开始我们先通过交互解释模块来解析输入的命令来执行相应的操作,然后便进行进程的管理(进程的创建和删除)和资源的管理(资源的申请和释放),在下面每个具体的模块设计将进行详细的设计介绍。
51 |
52 | #### 3.1 Test shell 模块:
53 | 首先是 shell 模块的设计,此模块主要的功能是解析用户输入的指令,然后执行相应的操作。在代码中我们设计一个类来表示 shell,然后读入用户的输入来执行对应的操作。下面具体类信息和代码流程细节,其中关于进程和资源模块不做详细说明。
54 |
55 | ##### 3.1.1 模块类:
56 | - 交互界面 shell:
57 | - 读入用户输入,执行相应的操作:read()
58 |
59 | ##### 3.1.2 细节说明:
60 | ###### 系统启动初始化:Shell()
61 | 通过 shell 类的构造函数进行系统的初始化,在初始化中,调用 init() 函数创建初始进程(优先级为0的系统进程):
62 |
63 | ```c++
64 | Shell::Shell() {
65 | ProcessManage::init();
66 | instruck = NULL;
67 | }
68 | ```
69 |
70 | ###### 对用户输入指令进行解析执行:read(std::string input)
71 | 读入用户的输入,使用字符分割获取指令的各个部分,然后对指令进行判断(是什么指令,指令参数是否符合规范),指令正确时安装相应指令调用相应的函数:
72 |
73 | ```c++
74 | /************************************************************************/
75 | /* 读取用户指令进行相应操作:
76 | input:用户输入的指令*/
77 | /************************************************************************/
78 | bool Shell::read(std::string s) {
79 | int input = 0;
80 |
81 | //对输入的指令进行分割解析
82 | instruck = new std::vector;
83 | std::string delim = " ";//分隔符为空格
84 | Tool::split(s, delim, instruck);
85 |
86 | //获取命令
87 | std::string command = instruck->at(0);
88 |
89 | //匹配的同时进行指令参数检测(是否符合标准或个数是否匹配)
90 | //退出系统
91 | if(command == "q") {
92 | if(instruck->size() == 1) {
93 | return false;
94 | }
95 | }
96 | //创建进程
97 | else if(command == "cr") {
98 | //判断是否参数为两个,一个进程 ID,一个进程优先级
99 | if(instruck->size() != 3) {
100 | std::cout << ">>创建进程需提供进程名和优先级,请检查输入参数" << std::endl;
101 | std::cout << ">>";
102 | }
103 | else {
104 | std::string name = instruck->at(1);
105 | int priority = atoi(instruck->at(2).c_str());
106 | ProcessManage::createProcess(name, priority);
107 | }
108 | }
109 | //删除进程
110 | else if(command == "de") {
111 | //判断参数是否为一个,删除进程名
112 | if(instruck->size() != 2) {
113 | std::cout << ">>删除进程需提供进程名,请检查输入参数" << std::endl;
114 | std::cout << ">>";
115 | }
116 | else {
117 | std::string name = instruck->at(1);
118 | ProcessManage::deleteProcess(name);
119 | }
120 | }
121 | //申请资源
122 | else if(command == "req") {
123 | //判断参数是否为两个,资源名和申请资源数量
124 | if(instruck->size() != 3) {
125 | std::cout << ">>申请需提供资源名和数量,请检查输入参数" << std::endl;
126 | std::cout << ">>";
127 | }
128 | else {
129 | std::string name = instruck->at(1);
130 | int count = atoi(instruck->at(2).c_str());
131 | ResourceManage::requestResource(name, count);
132 | }
133 | }
134 | //释放资源
135 | else if(command == "rel") {
136 | //判断参数是否为一个:资源名
137 | if(instruck->size() != 2) {
138 | std::cout << ">>释放需提供资源名,请检查输入参数" << std::endl;
139 | std::cout << ">>";
140 | }
141 | else {
142 | std::string name = instruck->at(1);
143 | ResourceManage::releaseResource(name);
144 | }
145 | }
146 | //时钟中断
147 | else if(command == "to") {
148 | if(instruck->size() != 1) {
149 | std::cout << ">>请检查输入,help查看指令输入帮助" << std::endl;
150 | std::cout << ">>";
151 | }
152 | else {
153 | ProcessManage::timeInt();
154 | }
155 | }
156 | //查看进程信息
157 | else if(command == "list_p") {
158 | if(instruck->size() != 1) {
159 | std::cout << ">>请检查输入,help查看指令输入帮助" << std::endl;
160 | std::cout << ">>";
161 | }
162 | else {
163 | ProcessManage::listProcess();
164 | }
165 | }
166 | //查看系统资源信息
167 | else if(command == "list_r") {
168 | if(instruck->size() != 1) {
169 | std::cout << ">>请检查输入,help查看指令输入帮助" << std::endl;
170 | std::cout << ">>";
171 | }
172 | else {
173 | ResourceManage::listResource();
174 | }
175 | }
176 | //输入错误
177 | else {
178 | std::cout << ">>请检查输入,help查看指令输入帮助" << std::endl;
179 | std::cout << ">>";
180 | }
181 |
182 | //释放相应指针资源
183 | delete(instruck);
184 |
185 | return true;
186 | }
187 | ```
188 |
189 | #### 3.2 进程模块:
190 | 进程模块较为复杂,以下活动有几个要点需要注意:
191 | - 进程初始化:进程初始化时系统会自动创建一个初始进程,其优先级为0,最高优先级,是后面所有进行的父进程
192 | - 进程创建:创建一个新的进程会导致一次进程调度,重新检查进程的优先级,如果当前新建的进程的优先级比正在运行的进程的优先级高,那么当前正在运行的进程停止运行,进入就绪等待队列,新建进程运行
193 | - 删除进程:删除一个进程,也会导致一次进程调度,因为删除一个进程后会释放相应获得的资源,而其他进程可也申请相应的资源而进入就绪队列
194 | - 时钟中断:停止当前运行的进程,让其进入就绪等待队列,再让下一进程进入运行
195 |
196 | 进程优先级有三级,依次下降,0级只有初始化进程:0级、1级、2级
197 |
198 | 进程的状态有三种:阻塞(-1)、就绪(0)、运行(1)。阻塞是因资源无法获取;就绪是资源获取后在队列中排队等待;运行是进行正在运行,系统在同一时间只能运行一个进程
199 |
200 | 新建进程是资源获取数量为随机生成
201 |
202 | ##### 3.2.1 模块类:
203 | - 进程管理 ProgressManage:
204 | - 系统进程初始化:init()
205 | - 创建进程:createProcess()
206 | - 删除进程:deleteProcess()
207 | - 查看进程信息:listProcess()
208 | - 时钟中断:timeInt()
209 |
210 | - 进程 Progress:
211 | - 进程名:name
212 | - 所需资源:resource1, resuouce2
213 | - 优先级:priority
214 | - 进程状态:state
215 |
216 | - 进程控制块结构 PCB:
217 | - 进程:pProgress
218 | - 父进程:pFather
219 | - 子进程:pSon
220 | - 队列中的上一个进程:fore
221 | - 队列中的下一个进程:next
222 | - 资源状态:sourceState
223 |
224 | ##### 3.2.2 实现细节:
225 | ###### 进程创建:
226 | 创建进程如下:首先要确定新建的进程为重名,然后新建进程,打印相应信息;新建的进程首先进入就绪队列,如果优先级较高,可强占运行时间
227 |
228 | ```c++
229 | /************************************************************************/
230 | /* 创建进程:
231 | name:新建进程名
232 | priority:新建进程优先级*/
233 | /************************************************************************/
234 | bool ProcessManage::createProcess(std::string name, int priority) {
235 | //首先检查是否重复创建相同名称的进程
236 | PCB* isRepeat = NULL;
237 | isRepeat = find(name);
238 | if(isRepeat != NULL) {
239 | std::cout << ">>当前进程名已存在,请重新命名进程名" << std::endl;
240 | return false;
241 | }
242 |
243 | int rA = -1;
244 | int rB = -1;
245 |
246 | MyProcess* process = new MyProcess(name, priority);
247 | process->getResourceNeed(rA, rB);
248 | PCB* pcb = new PCB(process);
249 |
250 | std::cout << ">>进程: " << name << " 创建成功,优先级为:" << priority
251 | << " 资源A、B需求量为:" << rA << "、" << rB << std::endl;
252 |
253 | //父子关系建立
254 | //如果当前有运行进程,则此新建进程为此运行进程的子进程,如果没有,则是初始进程的子进程
255 | if(runningProcess == NULL) {
256 | initProcess->setSon(pcb);
257 | pcb->setFather(initProcess);
258 | }
259 | else {
260 | runningProcess->setSon(pcb);
261 | pcb->setFather(runningProcess);
262 | }
263 |
264 | //新建进程后将其添加入就绪队列
265 | addReadyQueue(pcb);
266 |
267 | return true;
268 | }
269 | ```
270 |
271 | ###### 删除进程:
272 | 删除进程时首先判断系统中是否存在这个进程,并且释放其占用的资源,然后销毁此进程和他的子进程,如果进行一次系统调度
273 |
274 | ```c++
275 | /************************************************************************/
276 | /* 删除进程:
277 | name:删除的进程名*/
278 | /************************************************************************/
279 | bool ProcessManage::deleteProcess(std::string name) {
280 | //查看是否存在这个进程
281 | PCB* destroyProcess = find(name);
282 | if(destroyProcess == NULL) {
283 | std::cout << ">>系统中无此进程,请检查输入" << std::endl;
284 |
285 | return true;
286 | }
287 | else {
288 | destroy(destroyProcess);
289 | schedule();
290 | }
291 |
292 | return true;
293 | }
294 |
295 | /************************************************************************/
296 | /* 销毁进程,连同其子进程:
297 | pcb:销毁的进程*/
298 | /************************************************************************/
299 | bool ProcessManage::destroy(PCB* pcb) {
300 | //首先查看此进程是否有子进程,如果有子进程,先销毁子进程
301 | if(pcb->getSon() != NULL) {
302 | destroy(pcb->getSon());
303 | }
304 |
305 | //释放删除进程的资源
306 | ResourceManage::releaseResource(pcb);
307 |
308 | //销毁当前进程
309 | //去除相应的父子关系
310 | PCB* father = pcb->getFather();
311 | PCB* son = pcb->getSon();
312 | if(father != NULL && son == NULL) {
313 | father->setSon(NULL);
314 | }
315 |
316 | //去除队列信息
317 | std::string name = pcb->getProcess()->getName();
318 | //就绪队列寻找
319 | PCB* current = readyQueue;
320 | while(current != NULL) {
321 | if(current->getProcess()->getName() == name) {
322 | PCB* fore = current->getFore();
323 | PCB* next = current->getNext();
324 | //如果当前进程位于队首,并且不止一个进程
325 | if(fore == NULL && next != NULL) {
326 | readyQueue = next;
327 | next->setFore(fore);
328 | runningProcess = NULL;
329 |
330 | delete(pcb);
331 | std::cout << ">>进程: " << name << " 删除成功";
332 | std::cout << " 正在运行的进程被删除" << std::endl;
333 | return true;
334 | }
335 | //如果当前进程位于队首,并且只有一个进程
336 | else if(fore == NULL && next == NULL) {
337 | readyQueue = NULL;
338 | runningProcess = NULL;
339 |
340 | delete(pcb);
341 | std::cout << ">>进程: " << name << " 删除成功";
342 | std::cout << " 正在运行的进程被删除" << std::endl;
343 | return true;
344 | }
345 | //如果当前进程位于队尾
346 | else if(fore != NULL && next == NULL) {
347 | fore->setSon(NULL);
348 |
349 | delete(pcb);
350 | std::cout << ">>进程: " << name << " 删除成功" << std::endl;
351 | return true;
352 | }
353 | //进程位于中间
354 | else if(fore != NULL && next != NULL) {
355 | fore->setNext(next);
356 | next->setFore(fore);
357 |
358 | delete(pcb);
359 | std::cout << ">>进程: " << name << " 删除成功" << std::endl;
360 | return true;
361 | }
362 | }
363 |
364 | current = current->getNext();
365 | }
366 |
367 | //阻塞队列寻找
368 | current = blockQueue;
369 | while(current != NULL && pcb != NULL) {
370 | if(current->getProcess()->getName() == name) {
371 | PCB* fore = current->getFore();
372 | PCB* next = current->getNext();
373 | //如果当前进程位于队首,并且不止一个进程
374 | if(fore == NULL && next != NULL) {
375 | blockQueue = next;
376 | next->setFore(fore);
377 |
378 | delete(pcb);
379 | std::cout << ">>进程: " << name << " 删除成功" << std::endl;
380 | return true;
381 | }
382 | //如果当前进程位于队首,并且只有一个进程
383 | else if(fore == NULL && next == NULL) {
384 | blockQueue = NULL;
385 |
386 | delete(pcb);
387 | std::cout << ">>进程: " << name << " 删除成功" << std::endl;
388 | return true;
389 | }
390 | //如果当前进程位于队尾
391 | else if(fore != NULL && next == NULL) {
392 | fore->setSon(NULL);
393 |
394 | delete(pcb);
395 | std::cout << ">>进程: " << name << " 删除成功" << std::endl;
396 | return true;
397 | }
398 | //进程位于中间
399 | else if(fore != NULL && next != NULL) {
400 | fore->setNext(next);
401 | next->setFore(fore);
402 |
403 | delete(pcb);
404 | std::cout << ">>进程: " << name << " 删除成功" << std::endl;
405 | return true;
406 | }
407 | }
408 |
409 | current = current->getNext();
410 | }
411 |
412 | return false;
413 | }
414 | ```
415 |
416 | ###### 进程调度:
417 | 在进程调度中,首先查找阻塞队列,看是否有足够的空闲资源,如果有空闲的充足资源,则把相应的进程激活,加入就绪队列
418 |
419 | ```c++
420 | ************************************************************************/
421 | /* 进程调度:*/
422 | /************************************************************************/
423 | void ProcessManage::schedule() {
424 | //首先检查阻塞队列是否可以获得资源而激活
425 | PCB* current = blockQueue;
426 | while(current != NULL) {
427 | //如果资源充足,进程进入就绪队列
428 | if(current->applyForResource(false)) {
429 | //从阻塞队列中移除
430 | std::string name = current->getProcess()->getName();
431 | PCB* fore = current->getFore();
432 | PCB* next = current->getNext();
433 | //如果当前进程位于队首,并且不止一个进程
434 | if(fore == NULL && next != NULL) {
435 | blockQueue = next;
436 | next->setFore(fore);
437 |
438 | std::cout << ">>进程: " << name << "进入就绪队列" << std::endl;
439 | addReadyQueue(current);
440 | return;
441 | }
442 | //如果当前进程位于队首,并且只有一个进程
443 | else if(fore == NULL && next == NULL) {
444 | blockQueue = NULL;
445 |
446 | std::cout << ">>进程: " << name << "进入就绪队列" << std::endl;
447 | addReadyQueue(current);
448 | return;
449 | }
450 | //如果当前进程位于队尾
451 | else if(fore != NULL && next == NULL) {
452 | fore->setSon(NULL);
453 |
454 | std::cout << ">>进程: " << name << "进入就绪队列" << std::endl;
455 | addReadyQueue(current);
456 | return;
457 | }
458 | //进程位于中间
459 | else if(fore != NULL && next != NULL) {
460 | fore->setNext(next);
461 | next->setFore(fore);
462 |
463 | std::cout << ">>进程: " << name << "进入就绪队列" << std::endl;
464 | addReadyQueue(current);
465 | return;
466 | }
467 | }
468 |
469 | current = current->getNext();
470 | }
471 |
472 | //检查就绪队列,如果有进程存在,但无运行进程则申请资源
473 | if(readyQueue == NULL) {
474 | std::cout << ">>无就绪进程,无进程可调度运行" << std::endl;
475 | }
476 | if(readyQueue != NULL && runningProcess == NULL) {
477 | //对队首进程进行检测,如果成功则运行,失败进入阻塞队列
478 | std::string name = readyQueue->getProcess()->getName();
479 | //如果资源不足则进入阻塞队列
480 | if(!readyQueue->getState() && !readyQueue->applyForResource(false)) {
481 | //首先从就绪独立移除
482 | PCB* current = readyQueue;
483 | current->setNext(NULL);
484 | readyQueue = current->getNext();
485 | if(readyQueue == NULL) {
486 | runningProcess = NULL;
487 | readyLast = NULL;
488 | }
489 | else {
490 | readyQueue->setFore(NULL);
491 | }
492 | //加入阻塞队列
493 | addBlockQueue(current);
494 | std::string name = readyQueue->getProcess()->getName();
495 | std::cout << ">>进程: " << name << "进入阻塞队列" << std::endl;
496 |
497 | //无运行进程,再调度进程调度,查看就绪队列下一个进程
498 | schedule();
499 | }
500 | else {
501 | readyQueue->getProcess()->setState(1);
502 | runningProcess = readyQueue;
503 | //如果是第一次申请资源成功,则设置成功占用资源
504 | if(!readyQueue->getState()) {
505 | readyQueue->setState(true);
506 | }
507 | std::cout << ">>进程: " << name << "资源申请成功,进入运行状态" << std::endl;
508 | return;
509 | }
510 | }
511 | }
512 | ```
513 |
514 | ###### 时钟中断:
515 | 时钟中断时暂停当前运行的进程,并将当前运行的进程加入到就绪队列的尾部,但不释放其占有的资源。然后进行进程调度
516 |
517 | ```c++
518 | /************************************************************************/
519 | /* 时钟中断:*/
520 | /************************************************************************/
521 | bool ProcessManage::timeInt() {
522 | if(runningProcess == NULL) {
523 | std::cout << ">>当前无运行进程,不需时钟中断" << std::endl;
524 | return false;
525 | }
526 |
527 | std::cout << ">>进程:" << runningProcess->getProcess()->getName() << " 时钟中断" << std::endl;
528 | //如果就绪进程就只有一个,只设置不是运行状态就可
529 | if(readyQueue->getNext() == NULL) {
530 | runningProcess->getProcess()->setState(0);
531 | }
532 | //否则将运行进程停止,并插入就绪队列最后方
533 | else {
534 | //设置状态
535 | runningProcess->getProcess()->setState(0);
536 | //从队列中移除
537 | readyQueue = runningProcess->getNext();
538 | runningProcess->getNext()->setFore(NULL);
539 | //插入队尾
540 | PCB* current = runningProcess;
541 | readyLast->setNext(current);
542 | current->setFore(readyLast);
543 | current->setNext(NULL);
544 | readyLast = current;
545 | }
546 |
547 | runningProcess = NULL;
548 | schedule();
549 |
550 | return true;
551 | }
552 | ```
553 |
554 | ###### 查看进程信息:
555 | 打印出现系统的相关进程信息
556 |
557 | ```c++
558 | /************************************************************************/
559 | /* 查看进程列表:*/
560 | /************************************************************************/
561 | bool ProcessManage::listProcess() {
562 | std::cout << ">>进程列表如下:" << std::endl;
563 |
564 | if(runningProcess == NULL) {
565 | std::cout << ">>当前无运行进程" << std::endl;
566 | }
567 | else {
568 | std::cout << ">>当前运行进程为:" << runningProcess->getProcess()->getName() << std::endl;
569 | }
570 |
571 | PCB* current = readyQueue;
572 | if(current == NULL) {
573 | std::cout << ">>就绪队列为空,没有就绪进程" << std::endl;
574 | }
575 | else {
576 | std::cout << ">>就绪队列有如下进程:";
577 | while(current != NULL) {
578 | std::cout << current->getProcess()->getName() << " ";
579 | current = current->getNext();
580 | }
581 | std::cout << std::endl;
582 | }
583 |
584 | current = blockQueue;
585 | if(current == NULL) {
586 | std::cout << ">>阻塞队列为空,没有阻塞进程" << std::endl;
587 | }
588 | else {
589 | std::cout << ">>阻塞队列有如下进程:";
590 | while(current != NULL) {
591 | std::cout << current->getProcess()->getName() << " ";
592 | current = current->getNext();
593 | }
594 | std::cout << std::endl;
595 | }
596 |
597 | return true;
598 | }
599 | ```
600 |
601 | #### 3.3 资源模块:
602 | ##### 3.3.1 模块类:
603 | - 资源管理类 ResourceManage:
604 | - 资源A:resourceA
605 | - 资源B:resourceB
606 | - 资源A的剩余数量:remainA
607 | - 资源B的剩余数量:remainB
608 | - 资源申请:requestResource()
609 | - 具体进程资源申请:apply()
610 | - 资源释放:releaseResource()
611 | - 资源情况查看:listResource()
612 |
613 | - 资源类 Resource:基类
614 | - 资源总数量:amount
615 |
616 | - 资源A ResourceA:继承资源类
617 |
618 | - 资源B ResourceB:基础资源类
619 |
620 | ##### 3.3.2 实现细节:
621 | ###### 资源申请:
622 | 根据系统的进程的资源要求进行资源的申请,资源申请有两种形式,一个是只查看系统中是否有相应的充足的资源,资源的数量不做相应的变化;另一种是判断是否有相应的资源,并获取,相应的资源数量做相应的变化
623 |
624 | ```c++
625 | /************************************************************************/
626 | /* 申请系统资源:
627 | /************************************************************************/
628 | bool ResourceManage::requestResource() {
629 | //std::cout << ">>申请资源:" << name << std::endl;
630 | ProcessManage::schedule();
631 |
632 | return true;
633 | }
634 |
635 | /************************************************************************/
636 | /* 进程资源申请,申请成功则资源数量进行相应的变化:
637 | countA:资源A的申请数量
638 | countB:资源B的申请数量
639 | isGet:是否是资源数量进行相应的变化*/
640 | /************************************************************************/
641 | bool ResourceManage::apply(const int& countA, const int& countB, bool isGet) {
642 | if(countA <= remainA && countB <= remainB) {
643 | if(isGet) {
644 | remainA -= countA;
645 | remainB -= countB;
646 | }
647 | return true;
648 | }
649 |
650 | return false;
651 | }
652 | ```
653 |
654 | ###### 释放资源:
655 | 释放资源有两种调用形式,一种是无参数调用,此调用默认释放当前运行进程的资源(视此进程已运行完成);另一种是指定相应的进程并释放其占有的资源
656 |
657 | ```c++
658 | /************************************************************************/
659 | /* 释放对应资源:
660 | /************************************************************************/
661 | bool ResourceManage::releaseResource() {
662 | //获取当前运行进程的资源数目,并释放
663 | int runA = -1;
664 | int runB = -1;
665 | ProcessManage::getRunningResource(runA, runB);
666 | remainA += runA;
667 | remainB += runB;
668 |
669 | //重新调度进程
670 | ProcessManage::schedule();
671 |
672 | return true;
673 | }
674 |
675 | /************************************************************************/
676 | /* 释放对应资源:
677 | pcb:要释放资源的进程*/
678 | /************************************************************************/
679 | bool ResourceManage::releaseResource(PCB* pcb) {
680 | //检测此进程是否有占用资源,没有资源占用直接返回
681 | if(!pcb->getState()) {
682 | return false;
683 | }
684 |
685 | //获取当前运行进程的资源数目,并释放
686 | int runA = -1;
687 | int runB = -1;
688 | pcb->getProcess()->getResourceNeed(runA, runB);
689 | remainA += runA;
690 | remainB += runB;
691 |
692 | std::cout << ">>进程 " << pcb->getProcess()->getName() << " 资源释放成功" << std::endl;
693 |
694 | return true;
695 | }
696 | ```
697 |
698 | ###### 查看资源信息:
699 | 打印显示系统中相关的资源信息:
700 |
701 | ```c++
702 | /************************************************************************/
703 | /* 查看系统资源信息:*/
704 | /************************************************************************/
705 | bool ResourceManage::listResource() {
706 | std::cout << ">>系统资源信息如下:" << std::endl;
707 | std::cout << "ResourceA:amount=" << resourceA->getAmount() << " remain=" << remainA << std::endl;
708 | std::cout << "ResourceB:amount=" << resourceB->getAmount() << " remain=" << remainB << std::endl;
709 |
710 | return true;
711 | }
712 | ```
713 |
714 | ### 4.测试
715 | #### 4.1 测试输入如下:
716 | - cr firstProcess 2
717 | - list_r
718 | - cr secondProcess 1
719 | - list_r
720 | - list_p
721 | - de firstProcess
722 | - list_p
723 | - list_r
724 | - cr firstProcess 2
725 | - cr secondProcess 1
726 | - list_r
727 | - list_p
728 | - to
729 | - list_r
730 | - list_p
731 | - cr P3 2
732 | - cr P4 2
733 | - list_r
734 | - list_p
735 | - rel
736 | - list_r
737 | - list_p
738 | - cr P5 1
739 | - cr P6 1
740 | - list_r
741 | - list_p
742 |
743 | #### 4.1 测试结果如下:
744 |
745 | 
746 |
747 | 
748 |
749 | 
750 |
751 | ## 六、实验总结
--------------------------------------------------------------------------------