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

📄 jincheng.txt

📁 针对操作系统的进程调度而设计的一个优化算法.
💻 TXT
字号:
#include "stdio.h" 
#include <stdlib.h> 
#include <conio.h> 
#define getpch(type) (type*)malloc(sizeof(type)) 
#define NULL 0 
struct pcb { 
  char name[10]; 
  char state; 
  int super; 
  int ntime; 
  int rtime; 
  struct pcb* link; 
}*ready=NULL,*p; 
typedef struct pcb PCB; 
  
  
void sort()  
{ 
  PCB *first, *second; 
  int insert=0; 
  if((ready==NULL)||((p->super)>(ready->super))) 
  { 
    p->link=ready; 
    ready=p; 
  } 
  else  
  { 
    first=ready; 
    second=first->link; 
    while(second!=NULL) 
   } 
   if((p->super)>(second->super)) 
   {  
      p->link=second; 
      first->link=p; 
      second=NULL; 
      insert=1; 
   } 
   else  
   { 
      first=first->link; 
      second=second->link; 
   } 
   if(insert==0) first->link=p;  
}
 
void input() 
{ 
  int i,num; 
  printf("\n Please put the Process ID?\n"); 
  scanf("%d",&num); 
  for(i=0;i<num;i++) 
  { 
    printf("\n Process ID is:\n",i); 
    p=getpch(PCB); 
    printf("\n Process Name:"); 
    scanf("%s",p->name); 
    printf("\n Process Super :"); 
    scanf("%d",&p->super); 
    printf("\n Process Runtime:"); 
    scanf("%d",&p->ntime); 
    printf("\n"); 
    p->rtime=0;p->state='w'; 
    p->link=NULL; 
    sort();  
   } 
} 

void disp(PCB * pr)  
{ 
   printf("\n qname \t state \t super \t ndtime \t runtime \n"); 
   printf("|%s\t",pr->name); 
   printf("|%c\t",pr->state); 
   printf("|%d\t",pr->super); 
   printf("|%d\t",pr->ntime); 
   printf("|%d\t",pr->rtime); 
   printf("\n"); 
}
 
void check()  
{ 
   PCB* pr; 
   printf("\n ****Now Running Process is:%s",p->name);
   disp(p); 
   pr=ready; 
   printf("\n ****Now these Processes are ready:\n");  
   while(pr!=NULL) 
   { 
     disp(pr); 
     pr=pr->link; 
   } 
}
 
void destroy() 
{ 
   printf("\n Process [%d] is finished.\n",p->name); 
   free(p); 
} 

void running()  
{ 
   (p->rtime)++; 
   if(p->rtime==p->ntime) 
     destroy(); 
   else 
   { 
     (p->super)--; 
      p->state='w'; 
      sort(); 
    } 
} 

void main()
{ 
    int len,h=0; 
    char ch; 
    input(); 
    len=5; 
    while((len!=0)&&(ready!=NULL)) 
    { 
      ch=getchar();  
      h++; 
      printf("\n The execute number:%d \n",h); 
      p=ready; 
      ready=p->link; 
      p->link=NULL; 
      p->state='R'; 
      check(); 
      running(); 
      printf("\n Press any key continue ......"); 
      ch=getchar(); 
    } 
   printf("\n  Process has finished.  \n"); 
   ch=getchar(); 
}

⌨️ 快捷键说明

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