【问题标题】:How to implement a priority scheduler in xv6 ?如何在 xv6 中实现优先级调度程序?
【发布时间】:2015-03-10 19:33:43
【问题描述】:

在 xv6 中实现优先级调度算法?

但我无法理解如何处理其中的调度。 我可以使用此代码设置优先级。

int
set_priority(int pid,int priority)
{
  struct proc *p;
  //acquire(&ptable.lock);
  //cprintf("Set Priority - %d \n",priority);
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if((p->pid == pid) || (p->parent->pid == pid)){
      p->priority = priority;
      return 0;
    }
  }
  //release(&ptable.lock);
  return -1;
} 

【问题讨论】:

    标签: c scheduling xv6


    【解决方案1】:

    首先,您需要在struct proc中添加一个字段(优先级)。

    struct proc{
       //
      ....
      int priority; // priority of the process
    }
    

    其次,您现在可以在proc.c 中编写自己的调度程序。

    void scheduler(void){
        for(;;){
        //add your own priority scheduler here.
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多