第六次SPOOLING假脱机技术Word文件下载.docx

上传人:b****6 文档编号:17655717 上传时间:2022-12-07 格式:DOCX 页数:10 大小:55.28KB
下载 相关 举报
第六次SPOOLING假脱机技术Word文件下载.docx_第1页
第1页 / 共10页
第六次SPOOLING假脱机技术Word文件下载.docx_第2页
第2页 / 共10页
第六次SPOOLING假脱机技术Word文件下载.docx_第3页
第3页 / 共10页
第六次SPOOLING假脱机技术Word文件下载.docx_第4页
第4页 / 共10页
第六次SPOOLING假脱机技术Word文件下载.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

第六次SPOOLING假脱机技术Word文件下载.docx

《第六次SPOOLING假脱机技术Word文件下载.docx》由会员分享,可在线阅读,更多相关《第六次SPOOLING假脱机技术Word文件下载.docx(10页珍藏版)》请在冰豆网上搜索。

第六次SPOOLING假脱机技术Word文件下载.docx

2>

服务程序在将输出信息送输出井时,如发现输出井已满,将调用进程置为“等待状态1”。

3>

SPOOLING进程在进行输出时,若输出井空,则进入“等待状态2”。

4>

SPOOLING进程输出一个信息块后,应立即释放该信息快所占的输出井空间,并将正在等待输出的进程置为“可执行状态”。

5>

服务程序在输出信息到输出井并形成输出请求信息块后,若SPOOLING进程处于等待态则将其置为“可执行状态”。

6>

当用户进程声请请求输出块时,若没有可用请求块时,调用进程进入“等待状态3”。

(二)程序体系

1.main()函数

初始化输入井buffer:

初始化为0

for(i=0;

i<

2;

i++)

for(n=0;

n<

100;

n++)

buffer[i][n]=0;

初始化进程控制块pcb:

初始化为以下状态

for(i=0;

3;

{

structpcb*tmPcb=(structpcb*)malloc(sizeof(structpcb));

//开辟空间

tmPcb->

id=i;

status=0;

//状态

firstaddr=0;

length=0;

//长度

outbufword=1;

PCB[i]=tmPcb;

}

调度算法:

随机调度:

用户1与用户2的调度概率各为45%,SPOOLING进程输出程序的调度概率为10%

srand((unsigned)time(NULL));

//随机函数,利用系统时间做种子

while

(1)

i=rand()%100;

//产生1到100的随机数

重要函数:

voidrequest(inti)和voidspooling()

◆voidrequest(inti):

输出用户请求数据

while

(1)

{

j=rand()%10;

if(j==0)

{

run->

length=length;

break;

}

buffer[i-1][(run->

addr+length)]=s;

//输出请求数据

cout<

<

s<

"

"

;

s++;

length++;

}

◆voidspooling():

SPOOLING输出程序

run->

length;

i++)

printf("

%d"

buffer[run->

reqname-1][run->

addr+i]);

fprintf(f,"

(三)数据结构:

进程控制块PCB

structpcb

intstatus;

/*进程状态*/

}PCB[3];

请求输出块reqblock

struct{

intreuname;

}reqblock[10];

输出井BUFFER

SPOOLING系统为每个请求输出的进程在输出井中分别开辟一个区。

本实验可设计一个二维数组(intbuffer[2][10])作为输出井。

每个进程在输出井最多可占用10个位置。

(四)详细分析

为两个请求输出的用户进程设计两个输出井。

每个可存放10个信息,即buffer[2][10]。

当用户进程将其所有文件输出完时,终止运行。

为简单起见,用户进程简单地设计成:

每运行一次,随机输出数字0~9之间的一个数,当输入10个数时形成一个请求信息块,填入请求输出信息块reqblock结构中。

#include<

iostream.h>

stdio.h>

stdlib.h>

time.h>

intid;

/*进程标识数*/

/*进程状态*/

intfirstaddr;

/*信息块首地址*/

intlength;

/*本次输出信息长度*/

intoutbufword;

/*输出缓冲字*/

}*PCB[3];

FILE*f;

structreq/*请求输出块*/

intreqname;

/*请求进程名*/

intaddr;

/*信息在输出井的首地址*/

intbuffer[2][100];

intl1=1,l2=1;

inthead=0,tail=0;

intt1,t2;

voidrequest(inti)/*i为请求输出的进程标识1或2*/

intj,length=0,m;

structreq*run;

if(i==1)

t1--;

else

t2--;

cout<

用户"

请求数据:

\n"

run=&

reqblock[tail%10];

run->

reqname=i;

if(tail==0)

addr=0;

intindex=(tail-1)%10;

addr=reqblock[index].addr+reqblock[index].length;

for(m=0;

m<

m++)

if(buffer[i-1][m]==0)

run->

addr=m;

break;

ints=0;

while

(1)

j=rand()%10;

if(j==0)

buffer[i-1][(run->

//输出请求数据

cout<

s++;

length++;

endl;

PCB[i-1]->

length+=length;

if(PCB[2]->

status==2)

PCB[2]->

tail++;

voidspooling()

inti,j;

printf("

调用SPOOLING输出服务程序输出数据:

);

fprintf(f,"

run=&

reqblock[head%10];

用户%d\n"

run->

reqname);

for(i=0;

i<

i++)

printf("

head++;

for(j=0;

j<

j++)

if(PCB[j]->

status==1)

PCB[j]->

intmain()

inti,n;

f=fopen("

result.txt"

"

w"

n<

n++)

structpcb*tmpPcb=(structpcb*)malloc(sizeof(structpcb));

tmpPcb->

PCB[i]=tmpPcb;

Howmanyworkdop1wanttodo?

scanf("

%d"

&

t1);

%d\n"

t1);

Howmanyworkdop2wanttodo?

t2);

t2);

srand((unsigned)time(NULL));

if(i<

=45)

{

if((PCB[0]->

status==0)&

&

(t1>

0))

{

request

(1);

}

}

elseif((i<

=90)&

(t2>

if(PCB[1]->

status==0)

request

(2);

else

spooling();

if((t1==0)&

(t2==0)&

(head==tail))

break;

free(PCB[i]);

PCB[i]=NULL;

fclose(f);

return0;

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

当前位置:首页 > 小学教育 > 语文

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

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