| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4120 人关注过本帖
标题:关于进程调度算法
只看楼主 加入收藏
fenfen
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-5-11
收藏
 问题点数:0 回复次数:0 
关于进程调度算法

#include "stdio.h"

#include <stdlib.h>

#include <conio.h>

#define getpch(type) (type*)malloc(sizeof(type))

#define NULL 0

struct pcb { /* 定义进程控制块PCB */

char name[10];

char state[100];

int waittime; int xtime;

int ntime;

int rtime;

struct pcb* link;

}*ready=NULL,*p,*t=NULL;

typedef struct pcb PCB;

sort() /* 建立对进程进行优先级排列函数*/

{

p->link=ready; ready=p;

} sort1() {p->link=t; ready=p;

}

input() /* 建立进程控制块函数*/

{

int i,num;

clrscr(); /*清屏*/

printf("\n 请输入进程号:");

scanf("%d",&num);

for(i=0;i<num;i++)

{

printf("\n 进程号No.%d:\n",i);

p=getpch(PCB);

printf("\n 输入进程名:");

scanf("%s",p->name);

printf("\n阻塞进程的时间片 :");

scanf("%d",&p->waittime);

printf("\n 进程要运行的时间:");

scanf("%d",&p->ntime); printf("\n阻塞时间:"); scanf("%d",&p->xtime);

printf("\n");

p->rtime=0;

p->link=NULL;

sort(); /* 调用sort函数*/

}

}

int space()

{

int l=0; PCB* pr=ready;

while(pr!=NULL)

{

l++;

pr=pr->link;

}

return(l);

}

disp(PCB * pr) /*建立进程显示函数,用于显示当前进程*/

{

printf("\n qname \t state \t waittime \t ndtime \t runtime \t xtime\n");

printf("|%s\t",pr->name);

printf("|%c\t",pr->state);

printf("|%d\t",pr->waittime);

printf("|%d\t",pr->xtime);

printf("|%d\t",pr->ntime);

printf("|%d\t",pr->rtime);

printf("\n");

} check() /* 建立进程查看函数 */

{

PCB* pr; PCB* pp;

printf("\n当前正在运行的进程是:%s",p->name); /*显示当前运行进程*/

disp(p);

pr=ready;

printf("\n当前就绪队列状态为:\n"); /*显示就绪队列状态*/

while(pr!=NULL)

{

disp(pr);

pr=pr->link;

} pp=t;

printf("\n阻塞队列状态为:\n");

while(pp!=NULL)

{ disp(pp);

pp=pp->link; }

}

destroy() /*建立进程撤消函数(进程运行结束,撤消进程)*/

{

printf("\n 进程 [%s] 已完成.\n",p->name);

free(p);

}

running() /* 建立进程就绪函数(进程运行时间到,置就绪状态*/

{PCB *ptr; while(p->rtime!=p->ntime) {p->rtime++; printf("\n当前所运行的进程状态为:"); disp(p); ptr=t; while(ptr!=NULL) {ptr->xtime--; if(ptr->xtime==0) {p=ptr; sort(); } ptr->link=ptr; } if(p->rtime==p->waittime)

{ printf("\n该进程被阻塞:");

sort1();

break;} }

if(p->rtime==p->ntime) destroy();

}

main() /*主函数*/

{

int len,h=0;

input();

len=space(); printf("%d",len);

while((ready!=NULL))

{

h++;

printf("\n The execute number:%d \n",h);

p=ready;

ready=p->link;

check();

running();

printf("\n 按任一键继续......");

}

printf("\n\n 进程已经完成.\n");

} 帮我看一下有什么问题?

搜索更多相关主题的帖子: 算法 进程 int pcb PCB 
2005-05-11 22:25
快速回复:关于进程调度算法
数据加载中...
 
   



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

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