当前位置:首页 > 操作系统原理实验报告
printf(\进程名\\t优先级\\t轮数\\tcpu时间\\t需要时间\\t进程状态\\t计数器\\n\ while(p!=NULL) {
printf(\->needtime,p->state,p->count);
p = p->next; } p = finish; while(p!=NULL) {
printf(\->needtime,p->state,p->count);
p = p->next; } p = run; while(p!=NULL) {
printf(\->needtime,p->state,p->count);
p = p->next; } }
void InsertPrio(PCB *in) /*创建优先级队列,规定优先数越小,优先级越低*/ {
PCB *fst,*nxt; fst = nxt = ready;
if(ready == NULL) /*如果队列为空,则为第一个元素*/ {
in->next = ready; ready = in; }
else /*查到合适的位置进行插入*/ {
if(in ->prio >= fst ->prio) /*比第一个还要大,则插入到队头*/ {
in->next = ready; ready = in; } else {
while(fst->next != NULL) /*移动指针查找第一个别它小的元素的位置进行插入*/
{
nxt = fst; fst = fst->next; }
if(fst ->next == NULL) /*已经搜索到队尾,则其优先级数最小,将其插入到队尾即可*/
{
in ->next = fst ->next; fst ->next = in; }
else /*插入到队列中*/ { nxt = in;
in ->next = fst; } } } }
void InsertTime(PCB *in) /*将进程插入到就绪队列尾部*/ {
PCB *fst; fst = ready;
if(ready == NULL) {
in->next = ready; ready = in; } else {
while(fst->next != NULL) {
fst = fst->next; }
in ->next = fst ->next; fst ->next = in; } }
void InsertFinish(PCB *in) /*将进程插入到完成队列尾部*/ {
PCB *fst; fst = finish;
if(finish == NULL) {
in->next = finish; finish = in; } else {
while(fst->next != NULL) {
fst = fst->next; }
in ->next = fst ->next; fst ->next = in; } }
void PrioCreate() /*优先级调度输入函数*/ {
PCB *tmp; int i;
printf(\输入进程名字和进程所需时间:\\n\ for(i = 0;i < num; i++) {
if((tmp = (PCB *)malloc(sizeof(PCB)))==NULL) {
perror(\ exit(1); }
scanf(\
共分享92篇相关文档