• 大小: 951KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-26
  • 语言: 其他
  • 标签: 优先级。  

资源简介

操作系统进程调度算法 先来先服务 短作业优先 时间片轮转 优先级。有大量注释,帮助理解。目前没有错误

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 

struct pcb
{
int come_time;
int run_time;
int VIP;
char name[10];
struct pcb *next;
};

typedef struct pcb PCB;
void *creat(int n);
void Firstcome_Firstserve(PCB *head);
void Menue(PCB *headint n);
void*My_Copy(PCB *head);
void Print( PCB *headint len);
void Shortwork_Firstserve(PCB *head);
void TimeTurn_Firstserve(PCB *headint timeturnint n);
void VIP_Firstserve(PCB *head);


/************************************************************************/
/*                               *创建进程链表*                         */
/************************************************************************/ //2010_10_24
void *creat(int n)
{
PCB *head*p*q;

assert (head=(PCB*)malloc(sizeof(PCB)));  
p=head;
p->next=NULL;

while(n--)
{
p=head;
if( ( q=(PCB*)malloc(sizeof(PCB))) == NULL)
{
printf(“ERROR!\n“);
exit(0);
}
puts(“进程名:“);  
getchar();  
gets(q->name);
puts(“进程开始时间“);    
scanf(“%d“&q->come_time);
puts(“进程运行时间“);     
scanf(“%d“&q->run_time);
puts(“优先级“);
scanf(“%d“&q->VIP); 
if(p->next==NULL)          //在插入节点时排序
{
q->next=NULL;
p->next=q;
}
else
{
while (p->next!=NULL && q->come_time >p->next->come_time )
{
p=p->next;
}
q->next=p->next;
p->next=q;
}                           //在插入节点时排序
}
return head;
}


/************************************************************************/
/*                           拷贝链表                                   */
/************************************************************************/
void *My_Copy(PCB *head1)
{
PCB *head2=NULL; //新链表头结点
PCB *p2=NULL; //
PCB *p1=head1->next;
PCB *node=NULL;

assert(head2=(PCB*)malloc(sizeof(PCB)));
p2=head2;

while(p1!=NULL)
{
assert(node = (PCB*)malloc(sizeof(PCB)));

strcpy(node->namep1->name);  //拷贝进程
node->come_time=p1->come_time;
node->run_time=p1->run_time;
node->VIP=p1->VIP; //拷贝进程

node->next=NULL;     
p2->next=node;

p2=p2->next; //指针后移
p1=p1->next;
}
return head2;
}


/********************************打印输出*****************************************/
void Print(  PCB *headint len)
{
int i=0;

head=head->next;

puts(“进程名    到达时间     运行时间    优先级“);
for(i=0;inext)
{
printf(“%5s %10d %10d %10d\n“head->namehead->come_timehead->run_timehead->VIP);
}
}

/************************************************************************/
/*                            *先来先服务*                              */
/************************************************************************/ //2010_10_28
void Firstcome_Firstserve(PCB *head)
{
PCB *Head=My_Copy(head);
int counter=1;
PCB *h=Head->next;
PCB *p;
int time;         //进程结束时间
int time2;

while(h!=NULL)
{
if(h=

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     172071  2010-11-16 22:24  PCB\Debug\gaoke.exe

     文件     528288  2010-11-16 22:24  PCB\Debug\gaoke.ilk

     文件      38521  2010-11-16 22:24  PCB\Debug\gaoke.obj

     文件    2803084  2010-11-16 12:20  PCB\Debug\gaoke.pch

     文件     484352  2010-11-16 22:24  PCB\Debug\gaoke.pdb

     文件      50176  2010-11-17 23:03  PCB\Debug\vc60.idb

     文件      69632  2010-11-16 22:24  PCB\Debug\vc60.pdb

     文件      37074  2010-11-16 22:24  PCB\gaoke.c

     文件       3387  2010-11-06 19:06  PCB\gaoke.dsp

     文件        535  2010-11-06 20:55  PCB\gaoke.dsw

     文件      50176  2010-11-17 23:04  PCB\gaoke.ncb

     文件      49664  2010-11-17 23:04  PCB\gaoke.opt

     文件       1142  2010-11-16 22:24  PCB\gaoke.plg

     目录          0  2010-11-18 12:11  PCB\Debug

     目录          0  2010-11-18 12:11  PCB

----------- ---------  ---------- -----  ----

              4288102                    15


评论

共有 条评论