操作系统实验1.docx

上传人:b****3 文档编号:5459089 上传时间:2023-05-08 格式:DOCX 页数:28 大小:512.35KB
下载 相关 举报
操作系统实验1.docx_第1页
第1页 / 共28页
操作系统实验1.docx_第2页
第2页 / 共28页
操作系统实验1.docx_第3页
第3页 / 共28页
操作系统实验1.docx_第4页
第4页 / 共28页
操作系统实验1.docx_第5页
第5页 / 共28页
操作系统实验1.docx_第6页
第6页 / 共28页
操作系统实验1.docx_第7页
第7页 / 共28页
操作系统实验1.docx_第8页
第8页 / 共28页
操作系统实验1.docx_第9页
第9页 / 共28页
操作系统实验1.docx_第10页
第10页 / 共28页
操作系统实验1.docx_第11页
第11页 / 共28页
操作系统实验1.docx_第12页
第12页 / 共28页
操作系统实验1.docx_第13页
第13页 / 共28页
操作系统实验1.docx_第14页
第14页 / 共28页
操作系统实验1.docx_第15页
第15页 / 共28页
操作系统实验1.docx_第16页
第16页 / 共28页
操作系统实验1.docx_第17页
第17页 / 共28页
操作系统实验1.docx_第18页
第18页 / 共28页
操作系统实验1.docx_第19页
第19页 / 共28页
操作系统实验1.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

操作系统实验1.docx

《操作系统实验1.docx》由会员分享,可在线阅读,更多相关《操作系统实验1.docx(28页珍藏版)》请在冰点文库上搜索。

操作系统实验1.docx

操作系统实验1

操作系统实验报告

OperatingSystemExperimentReport

 

教务处

2012年12月

实验一、Windows操作系统

一、实验目的

计算机管理、任务管理、查看了解注册表

二、实验目的

Windows是目前使用人数最多的操作系统、学习操作系统,对操作系统有更加深入的了解。

三、实验内容

1.Windows提供了那些人机交互的界面?

答:

在你电脑上你所看到的界面诸如资源管理器、回收站

2.观察Windows对应用程序运行的支持。

(1)Windows提供了几种方式启动应用程序?

答:

1、双击桌面快捷方式

2、开始—所有程序

3、打开和应用程序关联的文档

4、开始-运行

5、将快捷图标拖到开始菜单的启动里面,随机启动

6、右击图标点击“打开”

(2)Windows提供哪几种方式让用户改变应用程序外观?

答:

右击桌面上的应用程序图标→属性→快捷方式→更改图标。

外观额的改变可以通过编辑资源来实现。

(3)Windows提供了几种方式结束程序的运行?

答:

按ctrl+alt+delete,调出任务管理器,选定进程,按“结束进程”或者右击图标点击“退出”

3.了解Windows对应用程序的运行时对I/O支持。

系统中有多少个I/O设备?

多少种I/O控制方式?

能否确信应用程序I/O需要操作系统支持?

能体会到“设备独立性”吗?

答:

I/O设备

(1)用户读写设备:

显示器、键盘、鼠标、打印机

(2)机器读写设备:

磁盘、U盘、数据采集卡

(3)数据传输设备:

网卡、串口、CAN总线

 

4.观察资源管理器,记录你使用使用的机器的资源情况:

CPU内存磁盘分区及容量文件目录树及文件属性。

5.观察设备管理器,记录你使用使用的机器的设备的配置情况(启动控制面板,到管理工具,再到计算机管理,进入设备管理器)

6.控制面板中看看系统还能让我们控制什么,特别了解“系统”、“显示”、“添加硬件”、“添加/删除程序”、“语音控制”等。

7.启动任务管理器,观察Windows对多任务管理列出的应用程序与启动的是否一致,系统中有多少进程?

为什麽会有那么多进程而都不是应用程序?

程序是由多个进运行的,且里面很多是系统进程

8.启动Windows的注册表,检查系统配置和设置,初步了解注册表的作用。

 

实验二、进程管理

一、实验目的

模拟进程管理

二、实验目的

通过这次试验,加深对进程概念的理解,进一步掌握进程状态的转变、进程调度的策略。

三、实验内容

使用了PCB进行进程管理控制,建立三个基本的队列:

等待、执行、阻塞进行模拟。

操作系统的进程管理,模拟进程的调度,模拟用户的创建、执行、阻塞、挂起、唤醒等操作。

 

调时间因等待事件

度片到发生而唤醒

 

发生而睡眠

四、设计思路

1.建立一个结点,即PCB快包括用户标识域、指针域等。

2.建立三个队列(执行队列、就绪队列、等待队列)

3.根据进程状态转换实现对三个队列的具体操作

4.用switch选择语句选择状态

示例程序

#include"stdio.h"

#include"dos.h"

#include"stdlib.h"

#include"conio.h"

#include"windows.h"

#defineSEC3

#defineNULL0

typedefstructPCB

{

intPID;

intUID;

structPCB*next;

}PCB;

PCB*really,*excute,*wait;

/*createqueueheader*/

/*queueoperation入列*/

intenqueue(PCB*head,PCB*node)

{

PCB*p;

p=head;

if(p->next==NULL)

{

head->next=node;

return1;

}

while(p)

{

if(p->next==NULL)

{

p->next=node;

return1;

}

elsep=p->next;

}

}/*enqueue*/

/*dequeue出队列*/

PCB*dequeue(PCB*head)

{

PCB*p;

p=head;

if(p->next==NULL)

{

returnNULL;

}

else

{

p=p->next;

head->next=p->next;

p->next=NULL;

returnp;

}

}

voidcreate()

{

PCB*p;

p=(PCB*)malloc(sizeof(PCB));

p->next=NULL;

printf("inputPIDandUIDtoanewprocess\n");

scanf("%d%d",&p->PID,&p->UID);

if(enqueue(really,p))

printf("createaprocess:

PID=%dUID=%d\n",p->PID,p->UID);

else

printf("createFailed\n");

}

intfexcute()

{

PCB*p=dequeue(really);

if(p==NULL)

{

printf("NOprocessinqueue\n");

return0;

}

else

{

enqueue(excute,p);

printf("addaprocessintoreallyqueueprocess:

PID=%dUID=%d\n",p->PID,p->UID);

return1;

}

}

intsuspend()

{

PCB*p=dequeue(excute);

if(p==NULL)

{

printf("NOprocessinqueue\n");

return0;

}

else

{

enqueue(really,p);

printf("addaprocessintoreallyqueueprocess:

PID=%dUID=%d\n",p->PID,p->UID);

return1;

}

}

intwake()

{

PCB*p=dequeue(wait);

if(p==NULL)

{

printf("NOprocessinqueue\n");

return0;

}

else

{

enqueue(really,p);

printf("addaprocessintowaitreallyprocess:

PID=%dUID=%d\n",p->PID,p->UID);

return1;

}

}

intblock()

{

PCB*p=dequeue(excute);

if(p==NULL)

{

printf("NOprocessinqueue\n");

return0;

}

else

{

enqueue(wait,p);

printf("addaprocessintowaitqueueprocess:

PID=%dUID=%d\n",p->PID,p->UID);

return1;

}

}

intoutputqueue(PCB*head)

{

PCB*p;

if(head->next==NULL)

{

printf("queueisnull\n");

return1;

}

p=head->next;

while(p)

{

printf("PID=%dUID=%d\n",p->PID,p->UID);

p=p->next;

}

return0;

}

voidoutput()

{

printf("REALLYQUEUE:

\n");

outputqueue(really);

printf("EXCUTEQUEUE:

\n");

outputqueue(excute);

printf("WAITQUEUE:

\n");

outputqueue(wait);

}

intinit()

{

PCB*p;

really=(PCB*)malloc(sizeof(PCB));

really->next=NULL;

excute=(PCB*)malloc(sizeof(PCB));

excute->next=NULL;

wait=(PCB*)malloc(sizeof(PCB));

wait->next=NULL;

printf("_________PROCESSSECHUDLE_________\n");

printf("nowiniting............\n");

printf("inputPIDandUIDasinteger,00asover\n");

while

(1)

{

p=(PCB*)malloc(sizeof(PCB));

p->next=NULL;

scanf("%d%d",&p->PID,&p->UID);

if(p->PID==0&&p->UID==0)

break;

else

{

if(enqueue(really,p))

printf("newprocessPID=%dUID=%dadded!

\n",p->PID,p->UID);

elsereturn0;

}

}

return1;

}

intrun()

{

PCB*p=excute;

ints=SEC;

if(excute->next==NULL)

{

printf("noprocessinexcutequeue\n");

return0;

}

else

{

p=excute->next;

printf("systemwillsleep%dasprocessrunning\n",s);

Sleep(3);

printf("process:

PID=%dUID=%dexcutesuccessed..\n",p->PID,p->UID);

excute->next=p->next;

free(p);

}

}

voidleave()

{

PCB*p,*t;

while(really->next||excute->next||wait->next)

{

p=really->next;

while(p)

{

t=p->next;

free(p);

p=t;

}

really->next=NULL;

p=wait->next;

while(p)

{

t=p->next;

free(p);

p=t;

}

wait->next=NULL;

p=excute->next;

while(p)

{

t=p->next;

free(p);

p=t;

}

excute->next=NULL;

}

exit(0);

}

voidhelp()

{

printf("__________HELP_________\n");

printf("\t-hHELPshowhelpoption\n");

printf("\t-cCREATEcreateanewprocess,andputtoreallyqueue\n");

printf("\t-bBLOCKblockanewprocessinexcutequeue\n");

printf("\t-wWAKEwakeaprocessinwaitqueue\n");

printf("\t-eEXCUTEexcuteaprocessinreallyqueue\n");

printf("\t-sSUSPENDsuspendaprocessinexcutequeue\n");

printf("\t-oOUTPUToutputallprocessinqueue\n");

printf("\t-rRUNexcuteaprocessinexcutequeue\n");

printf("\t-xEXITexitthispogram\n");

printf("____________________________________\n");

printf("\ttype'H'willshowthismenu\n");

}

voidmain()

{

charCOMMAND=NULL;

if(init()!

=1)

{

printf("initfalied!

\n");

getch();

exit(0);

}

else

{

printf("init...OK\n");

output();

help();

}

while

(1)

{

printf(">");

scanf("%c",&COMMAND);

switch(COMMAND)

{

case'\n':

break;

case'H':

case'h':

help();break;

case'C':

case'c':

create();break;

case'B':

case'b':

block();break;

case'W':

case'w':

wake();break;

case'S':

case's':

suspend();break;

case'E':

case'e':

fexcute();break;

case'O':

case'o':

output();break;

case'X':

case'x':

leave();break;

case'R':

case'r':

run();break;

}

}

}

运行结果:

 

实验三、虚拟存储管理

一、实验题目

分页虚拟存储的页面淘汰算法

二、实验内容

通过编程实现FIFO淘汰算法功能,算出缺页率。

此题目学生自行独立编写

三、实验目的

深入理解FIFO算法

四、设计思路

1.两个个队列(页面对列、内存队列)

2.手动输入测试序列

3.对是否命中进行判断

五、测试数据

页面序列:

432143543215

页面数:

3;缺页率:

75%

页面数:

4;缺页率:

83.3%

程序如下

#include"iostream"

#include"iomanip"

#include"stdio.h"

#include"stdlib.h"

#include"conio.h"

usingnamespacestd;

#defineMax30

#defineSize10

voidInit(intBlock[],intm)

{inti;

for(i=0;i

{

Block[i]=-1;

}

}

voidcreat(intPage[],intn)

{inti;

for(i=0;i

{

cin>>Page[i];

}

}

voidFIFO(intPage[],intBlock[],intn,intm)

{

inti,j,max_stay=0;

floatcount=0;

intget=-1,flag=-1,block_num=-1;

inttime[Size];

for(i=0;i

{time[i]=0;

}

for(i=0;i

{for(j=0;j

{if(Block[j]==-1)

{

get=j;

break;

}

}

for(j=0;j

{if(Block[j]==Page[i])

{

flag=j;

break;

}

}

for(j=0;j

{

if(time[j]>max_stay)

{

max_stay=time[j];

block_num=j;

}

}

if(flag==-1)

{if(get!

=-1)

{

Block[get]=Page[i];

time[get]=0;

for(j=0;j<=get;j++)

{

time[j]++;

}

get=-1;

}

else

{

Block[block_num]=Page[i];

time[block_num]=0;

for(j=0;j

{

time[j]++;

}

block_num=-1;

max_stay=0;

count++;

}

}

else

{

for(j=0;j

{

time[j]++;

}

flag=-1;

}

for(j=0;j

{

cout<

}

cout<

}

if(n>m)

count=count+m;

cout<<"缺页中断次数为:

"<

cout<<"缺页率为:

"<

}

voidmain()

{intn,m,Page[Max],Block[Size];

cout<<"*******先进先出FIFO页面置换算法*******"<

cout<<"--------------------------------------"<

cout<<"*******(默认:

-1表示物理块空闲)*******"<

cout<

";

while

(1)

{cin>>m;

if(m>Size||m<1)

{

cout<<"警告:

输入的数据错误!

"<

cout<<"请重新输入物理块数:

";

}

elsebreak;

}

Init(Block,m);

cout<<"请输入总页面数(n<=30):

";

cin>>n;

cout<<"\n请输入页面号引用串:

";

creat(Page,n);

cout<<"FIFO算法过程如下:

"<

FIFO(Page,Block,n,m);

getchar();

getchar();

}

 

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

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2