⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sy3.cpp

📁 操作系统实验(设备管理)源码
💻 CPP
字号:

#include "stdio.h"
#define WELLSIZE 500
#define FALSE 0
#define TRUE 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 ebp=0,ebc=10,cbp=0,n;
     int wellsize=WELLSIZE,wellptr=0;
     double random()
     {double m;static int seed;
     if((m=seed)<0)m=-m;
     seed=(25173*seed+13849)%65536;
     return(m/32767.0);
     }

	 bool spoolserver(int p,int s)
	 {int k;
	 if(s>wellsize||ebc==0)
	    return(FALSE);
	 reqblock[ebp].reqid=p;
	 reqblock[ebp].size=s;
	 reqblock[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=FALSE;
	 return(TRUE);
	 }
     void userpro(int i)
     {static int j;
      int c;
      if(pcb[i].bufflag==FALSE){
	 pcb[i].bufflag=TRUE;
	 j=0;
	 c=0;
	 while(c==0&&j==0)
	   for( ;j<49;++j) {
	      c=(int)(random()*10.0);
	      userbuf[i-1][j]=c;
	      if(c==0)break;
	      }
	      if(c)userbuf[i-1][j]=0;
	}
      if(spoolserver(i,j+1))
	 if(--pcb[i].filec==0){
	    pcb[i].status='c';
	    printf("\nUser%d program is completed!\n",i);
	    }
	}

    void spoolout()
    {  int d,a,s,c;
       if(ebc<10){
	     d=reqblock[cbp].reqid;
	     a=reqblock[cbp].addr;
	     s=reqblock[cbp].size;
	     cbp=(++cbp)%10;
	     printf("\n User%d:file%d,file_size=%d,\ntext;",d,++f[d],s-1);
	     a%=WELLSIZE;
	     while((c=well[a++])!=0){
		 printf("%d",c);
		 a%=WELLSIZE;
       }
       printf("\n");
       n--;
       wellsize+=s;
       ebc++;
       }
      }

      void schedular()
      {double 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') spoolout();
	     if(n==0)break;
	     }
	  }
	 void main()
	 {int i,j;
	 printf("\n*****SPOLING SYSTEM*****\n");
	   for(i=0;i<WELLSIZE;i++)well[i]=0;
	     for(i=0;i<3;i++)
		for(j=0;j<50;j++)userbuf[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 is output files?",i);
		 scanf("%d",&pcb[i].filec);
		 n+=pcb[i].filec;
		 }
	       }
	       schedular();
	       printf("\nAll files have been outputd!\n");
	       printf("\n*****END*****\n");
	 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -