完整word版东北大学操作系统第一次实验报告.docx

上传人:b****5 文档编号:11743752 上传时间:2023-03-31 格式:DOCX 页数:16 大小:163.67KB
下载 相关 举报
完整word版东北大学操作系统第一次实验报告.docx_第1页
第1页 / 共16页
完整word版东北大学操作系统第一次实验报告.docx_第2页
第2页 / 共16页
完整word版东北大学操作系统第一次实验报告.docx_第3页
第3页 / 共16页
完整word版东北大学操作系统第一次实验报告.docx_第4页
第4页 / 共16页
完整word版东北大学操作系统第一次实验报告.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

完整word版东北大学操作系统第一次实验报告.docx

《完整word版东北大学操作系统第一次实验报告.docx》由会员分享,可在线阅读,更多相关《完整word版东北大学操作系统第一次实验报告.docx(16页珍藏版)》请在冰豆网上搜索。

完整word版东北大学操作系统第一次实验报告.docx

完整word版东北大学操作系统第一次实验报告

实验1:

熟悉Linux系统

一、题目:

熟悉Linux系统

二、目的:

熟悉和掌握Linux系统基本命令,熟悉Linux编程环境,为以后的实验打下基础。

1、启动、退出、ls(显示目录内容)、cp(文件或目录的复制)、mv(文件、目录更名或移动)、rm(删除文件或目录)、mkdir(创建目录)、rmdir(删除空目录)、cd(改变工作目录)…

2、C语言编辑、编译

三、内容及要求:

1、熟练掌握Linux基本文件命令;

2、掌握Linux编辑程序、对源代码进行编译、连接、运行及调试的过程;

3、认真做好预习,书写预习报告;

4、实验完成后要认真总结、完成实验报告。

四、内容及要求:

在Linux环境下编制、调试源程序的实际过程(每一步的具体说明)。

 

实验2:

进程状态

一、题目:

进程状态

二、目的:

自行编制模拟程序,通过形象化的状态显示,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容、组织的变化,理解进程与其PCB间的一一对应关系。

三、内容及要求

1、设计并实现一个模拟进程状态转换及其相应PCB组织结构变化的程序;

2、独立设计、编写、调试程序;

3、程序界面应能反映出在模拟条件下,进程之间状态转换及其对应的PCB组织的变化。

4、进程的状态模型(三状态、五状态、七状态或其它)可自行选择,

5、代码书写要规范,要适当地加入注释;

6、鼓励在实验中加入新的观点或想法,并加以实现;

7、认真进行预习,完成预习报告;

8、实验完成后,要认真总结,完成实验报告。

四、程序流程图

图4.1进程转换流程

五、使用的数据结构及其说明

structPCB//进程控制块PCB

{

charname;//名字标识

stringstate;//状态

inttime;//执行时间

};

typedefstructPCBElemType;

structQNode

{

ElemTypedata;

structQNode*next;

};//链式队列结点

typedefstructQNodeQNode;//结点

typedefstructQNode*PNode;

typedefstruct

{

PNodefrnt;

PNoderear;

}LinkQueue;//链式队列

六、程序源代码、文档注释及文字说明

#include

#include

#include

#include

usingnamespacestd;

structPCB//进程控制块PCB

{

charname;//名字标识

stringstate;//状态

inttime;//执行时间

};

typedefstructPCBElemType;

structQNode

{

ElemTypedata;

structQNode*next;

};//链式队列结点

typedefstructQNodeQNode;//结点

typedefstructQNode*PNode;

typedefstruct

{

PNodefrnt;

PNoderear;

}LinkQueue;//链式队列

voidInsert_Queue(LinkQueue&Q,ElemTypee)//插入

{

PNodeptr=(PNode)malloc(sizeof(QNode));

if(!

ptr)

{

cout<<"(Insert_Queue)动态分配结点失败!

\n";

exit

(1);

}

ptr->data=e;

ptr->next=NULL;

Q.rear->next=ptr;

Q.rear=ptr;

}

intInit_Queue(LinkQueue&Q)//初始化

{

Q.frnt=Q.rear=(PNode)malloc(sizeof(QNode));

if(!

Q.frnt)

exit

(1);

Q.frnt->next=NULL;

return0;

}

intDelete_Queue(LinkQueue&Q,ElemType&e)//删除(头结点删除法)

{

PNodeptr;

if(Q.frnt==Q.rear)//空队列

return1;

ptr=Q.frnt->next;//删除第一个元素

Q.frnt->next=ptr->next;

e=ptr->data;

if(Q.rear==ptr)

Q.rear=Q.frnt;

free(ptr);

return0;

}

intEmpty_Queue(LinkQueueQ)//判断是否为空队列,是1,否0

{

return(Q.frnt==Q.rear?

1:

0);

}

voidPrint_Queue(LinkQueue&Q)//打印队列元素

{

PNodeptr;

if(Q.frnt==Q.rear)//队列为空时,返回提示信息

{

cout<<"\t\tempty.\n";

}

else

{

ptr=Q.frnt->next;

while(ptr!

=NULL)

{

cout<<"\t\tProcess'sname:

"<data.name<

ptr=ptr->next;

}

}

}

voidPrint_State(LinkQueue&Q_Ready,LinkQueue&Q_Running,LinkQueue&Q_Blocked)

{

cout<<"\t-----------------------------\n";

cout<<"\n\tStatus_Ready:

\n";

Print_Queue(Q_Ready);

cout<<"\n\tStatus_Running:

\n";

Print_Queue(Q_Running);

cout<<"\n\tStatus_Blocked:

\n";

Print_Queue(Q_Blocked);

cout<<"\n\t-----------------------------\n";

}

voidTransision_Two(LinkQueue&Q1,LinkQueue&Q2)

{

ElemTypee;

if(Empty_Queue(Q1))

{

cout<<"\nERROR!

前一个队列为空!

.\n";

return;

}

Delete_Queue(Q1,e);

Insert_Queue(Q2,e);

}

intmain()

{

intnum;

charchoose;

ElemTypee;

LinkQueueQ_Ready,Q_Running,Q_Blocked;

Init_Queue(Q_Ready);

Init_Queue(Q_Blocked);

Init_Queue(Q_Running);

cout<<"\t请输入进入Ready态的进程数目:

";

cin>>num;

cout<

for(inti=1;i<=num;i++)

{

cout<<"\t第"<

cout<<"\n\t请输入进程名字:

";

cin>>e.name;

cout<<"\t请输入进程状态:

";

cin>>e.state;

cout<<"\t请输入进程时间:

";

cin>>e.time;

Insert_Queue(Q_Ready,e);

}

cout<<"\t***********************************进程状态转换分割线************************************\n";

cout<<"\tN=创建进程(New),D=调度(Dispatch),T=时间片到(Timeout),W=等待事件(EventWait),";

cout<<"\n\tC=事件发生(EventOccur),E=退出进程(Exit),P=输出各进程(Print),O=退出程序(Overgame)"<

cout<<"\t请选择操作(N,D,T,W,C,E,P,O):

";

cin>>choose;

while(choose!

='O')

{

switch(choose)

{

case'N':

//N=创建进程(New)

{

cout<<"\t请输入进入Ready态的进程数目:

";

cin>>num;

cout<

for(inti=1;i<=num;i++)

{

cout<<"\t第"<

cout<<"\n\t请输入进程名字:

";

cin>>e.name;

cout<<"\t请输入进程状态:

";

cin>>e.state;

cout<<"\t请输入进程时间:

";

cin>>e.time;

Insert_Queue(Q_Ready,e);

}

}

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'D':

//D=调度(Dispatch)

Transision_Two(Q_Ready,Q_Running);

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'T':

//T=时间片到(Timeout)

Transision_Two(Q_Running,Q_Ready);

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'W':

//W=等待事件(EventWait)

Transision_Two(Q_Running,Q_Blocked);

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'C':

//C=事件发生(EventOccur)

Transision_Two(Q_Blocked,Q_Ready);

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'E':

//E=退出进程(Exit)

if(Empty_Queue(Q_Running))

{

cout<<"\n\tReleaseError!

没有正在执行的进程.\n";

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

}

Delete_Queue(Q_Running,e);

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'P':

//P=输出各进程(Print)

Print_State(Q_Ready,Q_Running,Q_Blocked);

break;

case'O':

//O=退出程序(Overgame)

exit

(1);

default:

cout<<"输出不符合规则,请重新输入!

"<

break;

}

cout<<"\t***********************************进程状态转换分割线************************************\n";

cout<<"\tN=创建进程(New),D=调度(Dispatch),T=时间片到(Timeout),W=等待事件(EventWait),";

cout<<"\n\tC=事件发生(EventOccur),E=退出进程(Exit),P=输出各进程(Print),O=退出程序(Overgame)"<

cout<<"\t请选择操作(N,D,T,W,C,E,P,O):

";

cin>>choose;

}

return0;

}

七、运行结果及其说明

运行结果如下截图所示,在截图中相继调用了"N=创建进程(New),D=调度(Dispatch),T=时间片到(Timeout),W=等待事件(EventWait),C=事件发生(EventOccur),E=退出进程(Exit),P=输出各进程(Print),O=退出程序(Overgame)"命令。

 

八、程序使用说明

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1