📄 spooling.txt
字号:
#include<stdo.h>
#define WELLSIZE 500
#define FALSE 0
#define TURE 1
struct {
int id;
char status;
int bufflag;
int filec;
} pcb[4];
struct {
int reqid;
int size;
int addr;
} reqblock [10];
int well [WELLSIZE], userbuf[3][50],f[4];
int edp=0, ebc=10, cbp=0, n;
int wellsize=WELLSIZE, wellptr=0;
float random()
{ int m; static ine seed;
if ((m=seed)<0) m=-m;
seed=(25173*seed+13849)&65536;
return(m/32767.0);
}
useropro (i) /*User process, i:identifier */
int i;
{ static int j;
int c;
if (pcb [i] .bufflag==FALSE) {/* buffer is empet */
pcb [i] .bufflag=TRUE;
c=j=0
while (c==0 && j==0)
for ( ;j<49;++j){
c=(int) random () *10.0);
userbuf [i-1] [j] =0;
}
if (spoolserver (i,j_1))
if (-pcb [i] .status='c';
print ("\nUser%d PROGRAM is completed!\n",i);
}
}
spoolserver (p,s) /*p:identifier, s:size */
int p,s;
{
int k;
if (s>wellsize||ebc==0)
return (FALSE);
repblock [ebp] .reqid=p;
repblock [ebp] .size=s;
repblock [ebp] .addr=wellptr;
ebc-;
ebp= (++ebp)%10;
for (k=0; k<s; ++k) {
well [wellptr++] =userbuf [p-1] [k];
wellptr%=WELLSIZE;
}
wellsize-=s;
pcb [p].bufflag=FASLE;
return (TRUE);
}
spoolout ( ) /* SPOOLing output process */
{
int d,a,s,c;
if (ebc<10) {
d=reqblock [cbp].reqid;
a=reqblock [cbp].addr;
s=reqblock [cbp].size;
cbp= (++cbp)%10;
printf ("\nUser%d:file%d,file_size=%d,\ntest;",d,++f[d],s-1);
a%=WELLSIZE;
while ((c=well [a++]!=0) {
printf ("%d",c);
a%=WELLSIZE;
}
printf("\n");
n-;
wellsize+=s;
ebc++;
}
}
schcduler()
{
float x;
for( ; ; ){
x=random();
if (x<0.30&&pcb[1].status=='e') userpro(1);
else if (x>=0.30&&x<0.60&&pcb[2].status=='e') userpro(2);
else if (x>0.60&&x<0.90&&pcb[3].status=='e') userpro(3);
else if (x>0.90&&pcb[0].status=='e') userpro();
if (n==0) break;
}
}
main()
{int i.j;
printf("\n****SPOOLing SYSTEM****\n");
/*initialization*/
for (i=0; i<wellsize;i++) well[i]=0;
for(i=0;i<3;i++)
for(j=0;j<50;J++) UERBUF[i][j]=0;
for(i=0;i<4;i++){
pcb[i].id=i;
pcb[i].status='e';
if(i){
pcb[i].bufflag=FALSE;
printf('\nTHE number of user%d's output files?'.i);
scanf(%d".&pcb{i}.filec);
n+=pcb[i].filec;
}
}
scheduler();
printf("\nall files have been outputded!\n");
printf("\n**** end ****\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -