3

Implement a priority scheduling algorithm in xv6?

But i am unable to understand how to handle the scheduling in this. I am able to set the priorities using this code.

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;
} 
MIXAM
  • 41
  • 1
  • 4

1 Answers1

2

first, you need to add a field (priority)in struct proc.

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

second, you can write your own scheduler in proc.c now.

void scheduler(void){
    for(;;){
    //add your own priority scheduler here.
    }
}
hyang51
  • 75
  • 1
  • 9