操作系统实验报告Word下载.docx

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

操作系统实验报告Word下载.docx

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

操作系统实验报告Word下载.docx

i<

500;

i++)

printf("

child%d\n”,i);

while((p2=fork())==-1);

if(p2==0)

for(i=0;

500;

i++)

printf(“son%d\n”,i)

for(i=0,i<

500;

printf("

daughter%d\n”,i);

程序2>

stdio.()

intp1,p2,i;

while((pl=fork())==-1);

if(pl==0)

lockf(1,1,0),

for(i=0;

i++)printf((“child%dn”,i);

lockf(1,0,0);

while((p2=fork())==-1);

lockf(1,1,0);

for(i=0;

i++)printf(“son%d\n”,i);

i++)printf(“daughter%d\n”,i);

}

实验三实现进程的软中断通信

1.掌握基本的软中断通信方法。

2.利用系统调用signal()捕捉中断信号。

3.理解Linux系统中的进程通信的基本原理。

任务1程序>

intpl,p2,stdout;

while((p1=fork())==-1);

*创建进程p1*

if(p1>

0)

while((p2=fork())==-1);

if(p2>

wait_mark=1;

signal(SIGINT,stop);

*接收Del信号,并转stop*

waiting(0);

kill(p1,16);

*向p1发中断信号16*

kill(p2,17);

*向p2发中断信号17*

wait(0);

*同步*

printf(“parentprocessiskilled!

\n”)

exit(0);

signal(SIGINT,SIG_IGN);

********

signal(17,stop);

printf(“%d”,SIG_DFL);

waiting();

lockf(stdout,1,0);

printf(“childprocess2iskilledbyparent!

\n”);

lockf(stdout,0,0);

exit(0);

}

wait_mark=l;

signal(16,stop);

printf(%d”,SIG_DEL);

waiting();

lockf(stdout,1,0);

childprocess1iskilledbyparent!

\n”);

1ockf(stdout,0,0);

voidwaiting()

while(wait_mark!

=0);

voidstop()

wait_mark=0;

任务2程序>

#include<

unistd.”);

exit(0);

voidInt2()

printf(“childprocess2iskilled!

byparent\n”);

exit(0);

main()

intexitpid;

signal(SIGINT,SIG_IGN);

signal(SIGQUIT,SIG_IGN);

while((pid1=fork())=-1);

if(pid=0)

signal(SIGUSRl,Intl);

pause();

exit(0);

while((pid=fork())=-1);

if(pid2=0)

signal(SIGUSRl,Intl);

signal(SIGINT,SIG_IGN);

pause();

signal(SIGINT,IntDelete);

waitpid(-1,&

exitcode,0);

printf(“parentprocessiskilled\n”);

实验四进程的管道通信

1.了解系统调用pipe()的功能。

2.掌握进程的管道通信的实现。

3.进一步理解进程通信的基本原理

unistd.()

intfd[2];

charOutPipe[l00],InPipe[l00];

pipe(fd);

while((pidl=fork())==-1);

if(pidl==0)

lockf(fd[1],1,0);

sprintf(OutPipe,“child1processissendingmessage!

”);

write(fd[1],OutPipe,50);

sleep(5);

lockf(fd[1],0,0);

while((pid2=fork())==-1);

if(pid2==0)

1ockf(fd[1],1,0);

sprintf(OutPipe,“child2processissendingmessage!

“);

write(fd[1],OutPipe,50);

sleep(5);

lockf(fd[l],0,0);

read(fd[0],InPipe,50);

printf(“%s\n”,InPipe);

wait(0);

read(fd[0],InPipe,50);

printf(“%s\n”,InPipe);

实验五使用动态优先权的进程调度算法模拟

一、实验目的

通过动态优先权算法的模拟加深对进程概念进程调度过程的理解。

二、实验内容

(1)用C语言来实现对N个进程采用动态优先权优先算法的进程调度。

(2)每个用来标识进程的进程控制块PCB用结构来描述,包括以下字段:

1,进程标识数ID。

2,进程优先数PRIORITY,并规定优先数越大的进程,其优先权越高。

3,进程已占用的CPU时间CPUTIME。

4,进程还需占用的CPU时间ALLTIME。

当进程运行完毕时,ALLTIME变为0。

5,进程的阻塞时间STARTBLOCK,表示当进程再运行STARTBLOCK个时间片后,将进入阻塞状态。

6,进程被阻塞的时间BLOCKTIME,表示已足赛的进程再等待BLOCKTIME个时间片后,将转换成就绪状态。

7,进程状态START。

8,队列指针NEXT,用来将PCB排成队列。

(3)优先数改变的原则:

1,进程在就绪队列中呆一个时间片,优先数加1。

2,进程每运行一个时间片,优先数减3。

(4)假设在调度前,系统中有5个进程,它们的初始状态如下:

ID

1

2

3

4

PRIORITY

9

38

30

29

CPUTIME

ALLTIME

6

STARTBLOCK

-1

BLOCKTIME

STATE

READY

(3)为了清楚的观察各进程的调度过程,程序应将每个时间片内的情况显示出来,参照的具体格式如下:

RUNNINGPROG:

i

READY-QUEUE:

-〉id1-〉id2

BLOCK-QUEUE:

-〉id3-〉id4

===========================================

ID01234

PRIORITYP0P1P2P3P4

CUPTIMEC0C1C2C3C4

ALLTIMEA0A1A2A3A4

STARTBLOCKT0T1T2T3T4

BLOCKTIMEB0B1B2B3B4

STATES0S1S2S3S4

三,实验步骤:

#include<

stdio.(inttime);

enumSTATE{Ready,Run,Block,RunOut};

structPROCESS{

intID;

intPriority;

intCputime;

intAlltime;

intStartblock;

intBlocktime;

enumSTATEState;

}Process[N];

intREADY[N];

intBLOCK[N];

intRUNOUT[N][2];

intmain(){

intTime=0;

init();

printf("

Time:

%d\n"

Time);

sort();

print();

while

(1){

Time++;

getchar();

if(run(Time))

break;

sort();

print(Time);

return0;

voidinit()

inti;

Inputpropertiesof%dprocess(PRIORITY,ALLTIME,STARTBLOCK,BLOCKTIME):

\n"

N);

for(i=0;

i<

N;

++i){

READY[i]=-1;

BLOCK[i]=-1;

RUNOUT[i][0]=-1;

RUNOUT[i][1]=-1;

Process[i].ID=i;

Process[i].Cputime=0;

Process[i].State=Ready;

*printf("

Number%d:

"

i);

scanf("

%d,%d,%d,%d"

&

Process[i].Priority,&

Process[i].ltime,

&

Process[i].Startblock,&

Process[i].Blocktime);

*

Process[i].Startblock=-1;

Process[i].Blocktime=0;

Process[0].Priority=9;

Process[0].Alltime=3;

Process[0].Startblock=2;

Process[0].Blocktime=3;

Process[1].Priority=38;

Process[1].Alltime=3;

Process[2].Priority=30;

Process[2].Alltime=6;

Process[3].Priority=29;

Process[3].Alltime=3;

Process[4].Priority=0;

Process[4].Alltime=4;

voidprint()

if(getRunning()>

=0)

\tRUNNINGPROG:

%d\n"

getRunning());

\tREADY_QUEUE:

);

if(READY[i]>

->

%d"

Process[READY[i]].ID);

else{

}

\n\tBLOCK_QUEUE:

if(BLOCK[i]>

Process[BLOCK[i]].ID);

\n=====================================================\n"

ID\t"

\t%d"

Process[i].ID);

\nPRIORITY"

Process[i].Priority);

\nCPUTIME\t"

Process[i].Cputime);

\nALLTIME\t"

Process[i].Alltime);

\nSTARTBLOCK"

Process[i].Startblock);

}printf("

\nBLOCKTIME"

Process[i].Blocktime);

\nSTATE\t"

switch(Process[i].State){

case0:

\tReady"

case1:

\tRun"

if(Process[i].Alltime==0)

Process[i].State=RunOut;

elseProcess[i].State=Ready;

case2:

\tBlock"

case3:

\tRunOut"

\tRUNOUTLIST:

if(RUNOUT[i][0]>

%d(%d)"

Process[RUNOUT[i][0]].ID,RUNOUT[i][1]);

intgetRunning()

if(Process[i].State==Run)

returni;

if(Process[i].Startblock==0)

return-1;

voidsort()

inti,j,k;

if(Process[i].State==Ready||Process[i].State==Run){

Process[i].State=Ready;

continue;

for(j=0;

j<

++j){

if(READY[j]<

READY[j]=i;

elseif(Process[i].Priority<

=Process[READY[j]].Priority)

{continue;

for(k=N-1;

k>

j;

--k){

READY[k]=READY[k-1];

elseif(Process[i].State==Block){

if(BLOCK[j]<

BLOCK[j]=i;

elseif(Process[i].Blocktime>

=Process[BLOCK[j]].Blocktime)

BLOCK[k]=BLOCK[k-1];

intrun(inttime)

inti,runNum;

runNum=READY[0];

if(runNum<

0&

BLOCK[0]<

0){

EveryprocessisOVER!

return1;

if(runNum>

=0){

Process[runNum].Priority-=3;

Process[runNum].Alltime-=1;

Process[runNum].Cputime+=1;

Process[runNum].State=Run;

if(i!

=runNum){

if(Process[i].State==Ready){

Process[i].Priority+=1;

Process[i].Blocktime-=1;

if(Process[i].Blocktime==0){

if(Process[runNum].Alltime==0)

Process[runNum].State=RunOut;

if(RUNOUT[i][0]<

RUNOUT[i][0]=runNum;

RUNOUT[i][1]=time;

elseif(Process[runNum].Startblock>

Process[runNum].Startblock-=1;

if(Process[runNum].Startblock==0){

Process[runNum].State=Block;

Process[runNum].Startblock-=1;

elseif(BLOCK[0]>

if(Process[i].State==Block){

print();

四,实验总结:

通过操作系统的实验,我学到了很多,我学会了学以致用,但这还不足,还应该继续努力,多动手多用脑,把知识用于实践中去,学习是无止境的,即使操作系统结课了,但我依旧会在以后的时间尽量去多学点有关操作系统的知识。

3.了解系统调用pipe()的功能。

4.掌握进程的管道通信的实现。

进一步理解进程通信的基本原理实验六使用动态分区分配方式的模拟

实验目的

了解动态分区分配方式中使用的数据结构和分配算法,并进一步加深对动态分区存储管理方式及其实现过程的理解。

实验内容

1.用C语言分别实现采用首次适应算法和最佳适应算法的动态分区分配过程alloc()和回收过程free()。

其中,空闲分区通过空闲分区链来管理:

在进行内存分配时,系统优先使用空闲区低端的空间。

2.假设初始状态下,可用的内存空间为640KB,并有下列的请求序列:

•作业1申请130KB。

•作业2申请60KB。

•作业3申请100KB。

•作业2释放60KB。

•作业4申请200KB。

•作业3释放100KB。

•作业1释放130KB。

•作业5申请140KB。

•作业6申请60KB。

•作业7申请50KB。

•作业6释放60KB。

请分别采用首次适应算法和最佳适应算法,对内存块进行分配和回收,要求每次分配和回收后显示出空闲分区链的情况。

【实验结果】

#include"

stdio.;

intEnd;

intSpace;

structMEMORY*next;

};

structWORK{

intID;

enumACTIO

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

当前位置:首页 > 临时分类 > 批量上传

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

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