东北大学操作系统实验三报告Word下载.docx
- 文档编号:4299355
- 上传时间:2023-05-03
- 格式:DOCX
- 页数:13
- 大小:17.08KB
东北大学操作系统实验三报告Word下载.docx
《东北大学操作系统实验三报告Word下载.docx》由会员分享,可在线阅读,更多相关《东北大学操作系统实验三报告Word下载.docx(13页珍藏版)》请在冰点文库上搜索。
为简单起见,每次产生的数据为0-99的整数,从0开始,顺序递增。
两个进程的调度是通过运行者使用键盘来实现的。
4.程序使用的数据结构
进程控制块:
包括进程名,进程状态和执行次数。
缓冲区:
一个整数数组。
缓冲区说明块:
包括类型,读指针,写指针,读等待指针和写等待指针。
5.程序使用说明
启动程序后,如果使用'
p'
键则运行一次生产者进程,使用'
c'
键则运行一次消费者进程。
通过屏幕可以观察到两个进程的状态和缓冲区变化的情况。
6.实验流程图
源程序
#include<
>
#definePIPESIZE8
enumStatus{RUN,WAIT,READY};
#defineNORMAL0
#defineSLEEP1
#defineAWAKE2
structPCB
{
charname[3];
enumStatusstatus;
inttime;
};
structwaitqueue
structPCBpcb;
structwaitqueue*next;
structPCB*producer;
/*writewaitpoint*/
structPCB*consumer;
/*readwaitpoint*/
structwaitqueue*headerqueue,*tailqueue;
intwriteptr;
intreadptr;
intwritein,readout;
intbuffer[PIPESIZE];
intempty,full;
voidrunp(charin[3]),runc(charin[3]),print();
intmain()
charin[3];
writeptr=0;
readptr=0;
writein=0;
empty=PIPESIZE;
full=0;
producer=(structPCB*)malloc(sizeof(structPCB));
consumer=(structPCB*)malloc(sizeof(structPCB));
headerqueue=(structwaitqueue*)malloc(sizeof(structwaitqueue));
headerqueue->
next=NULL;
tailqueue=headerqueue;
producer->
status=READY;
consumer->
status=WAIT;
time=consumer->
time=0;
printf("
Nowstartingtheprogram!
\n"
);
Press'
p1'
torunPRODUCER1,Press'
torunPRODUCER2\n"
c1'
torunCONSUMER1,Press'
c2'
torunCONSUMER2\n"
e'
toexitfromtheprogram.\n"
while
(1)
{
strcpy(in,"
N"
while(!
strcmp(in,"
))
{
printf("
scanf("
%s"
in);
if(strcmp(in,"
e"
)&
&
strcmp(in,"
p1"
p2"
c1"
c2"
{
printf("
error,pleaseinputagain!
!
strcpy(in,"
}
}
if('
==in[0])
runp(in);
producer->
time++;
elseif('
runc(in);
consumer->
else
n"
structwaitqueue*p=(structwaitqueue*)malloc(sizeof(structwaitqueue));
strcpy(p->
p->
=WAIT;
=producer->
time+1;
tailqueue->
next=p;
tailqueue=p;
full++;
}
else
writein=(writein+1)%100;
producer->
status=RUN;
printf("
runPRODUCER%sprocess.product%d"
in,writein);
buffer[writeptr]=writein;
if(empty>
8)
structwaitqueue*p;
p=headerqueue->
next;
runCONSUMER%sprocess.use%d"
p->
buffer[writeptr]);
if(tailqueue==p)
tailqueue=headerqueue;
headerqueue->
next=p->
free(p);
empty--;
if(writeptr>
readptr)
writeptr++;
if(writeptr>
=PIPESIZE)
{
writeptr=0;
if(readptr==0)
producer->
elseproducer->
}
else
if(writeptr==readptr)
producer->
elseproducer->
full++;
}
voidrunc(charin[3])
if(empty>
=8)
structwaitqueue*search;
search=headerqueue->
while(search!
=NULL)
if(!
strcmp(in,search->
)
error!
exit
(1);
search=search->
consumer->
CONSUMER%siswaiting,can'
tbescheduled.\n"
in);
=consumer->
empty++;
readout=buffer[readptr];
runCONSUMER%sprocess.use%d"
in,readout);
if(full>
writein=(writein+1)%100;
buffer[writeptr]=writein;
runPRODUCER%sprocess.product%d"
full--;
writeptr++;
readptr++;
if(readptr>
writeptr)
readptr++;
if(readptr>
readptr=0;
if(writeptr==0)
consumer->
else
elseconsumer->
if(readptr==writeptr)
consumer->
writeptr=readptr=0;
producer->
empty++;
voidprint()
inti=0;
intj=0;
intlow=0;
inthigh=0;
for(i;
i<
PIPESIZE;
i++)
--------"
if(readptr<
for(low=0;
low<
readptr;
low++)
||"
for(low=readptr;
writeptr;
|%2d|"
buffer[low]);
for(low=writeptr;
PIPESIZE;
elseif(readptr>
elseif(producer->
status==WAIT)
for(i=0;
if(producer->
status==WAIT&
NULL!
=headerqueue->
next)
structwaitqueue*p=headerqueue->
while(NULL!
=p)
PRODUCER%sprocessarewaitting\n"
;
p=p->
PRODUCERready\n"
if(consumer->
headerqueue->
CONSUMER%sprocessarewaitting\n"
CONSUMERready\n"
实验结果:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 东北大学 操作系统 实验 报告
![提示](https://static.bingdoc.com/images/bang_tan.gif)