| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 489 人关注过本帖
标题:请求大家帮个忙?
只看楼主 加入收藏
liguang6675
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-12-24
收藏
 问题点数:0 回复次数:1 
请求大家帮个忙?

我们操作系统作业:是用C实现进程调度,哪位能帮帮忙

搜索更多相关主题的帖子: 请求 
2005-12-24 20:04
liguang6675
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-12-24
收藏
得分:0 
我自己做了一个,就是不能运行,请求帮我看看
谢谢了!
#include<stdio.h>
#include<stdlib.h>
typedef enum{ready,block}two;
typedef struct pcb{int id;
int priority;
int cputime;
int blocktime;
two state;
struct pcb*next;}pcbnode;
typedef struct queue{pcbnode*front;
pcbnode*rear;
}queuetype;
queue ready,block;
int empty(queuetype*q)
{return(q->front==q->rear);}
void enqueue(queuetype*q,pcbnode*x)
{if(empty(q))
q->front=q->rear=x;
else{q->rear->next=x;
q->rear=x;}
}
void creatprocess(int t)
{ int i,a=60,b=1,c=30,d=1,n;
n=t;
for(i=0:i<n;i++)
{p=(pcbnode*)malloc(sizeof(pcbnode));
p.id=i;
p.cputime=b++;
p.next=null;
if(i<2n/3)
{p.priority=a--;
p.two=ready;
p.blocktime=0;
}
else {p.priority=c--;
p.two=block;
p.blocktime=d++;}
if(p.two==ready) enqueue(&ready,p);
else enqueue(&block,p);
}
pcbnode getmaxpriority(queuetype*q)
{pcbnode*p;
if(empty()) return null;
else{p=q->front->next;
return(p);}
void insertreadyqueue(ready*q,pcbnode*X)
{ pcbnode*r,s;
s=q->front;
if(empty()) q->front=q->rear=x;
else {
while((q->front->priority>x.priority)&&s)
{r=s;
s=s->next;}
if(S)
{r->next=x;
x->next=s;}
else
{s->next=x;
x->next=null;}
}
}
void delete(block*q,pcbnode*x)
{pcbnode*p;
p=q->front;
if(p&&p==x)
{p->next=p->next->next;
free(p);
}
else p=p->next;
}
void subblocktime(block*q)
{pcbnode*p;
p=q->front;
while(p)
{p.blocktime--;
if(p.blocktime==0) { delete(&block,p);
insert(&ready,p);
}
p=p->next;}
}
void print(queuetype*q)
{pcbnode*p;
p=q->front;
while(p)
{printf("%d%d%s\n",p.id,p.priority,p.state);
p=p->next;}
}
void control()
{int t=10,i=0;
pcbnode*p;
p=getmaxpriority();
while(t==0&&p)
{for(i=0;i<10;i++)
t--;
if(t==0){
p.priority-=3;
p.cputime--;
if(p.cputime==0) free(p);
else insert(&ready,p);
subblocktime();}
t=10;}
}
main()
{creatprocess(90);
control():
print(&ready);
print(&block);
}

2005-12-24 20:06
快速回复:请求大家帮个忙?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023012 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved