Question: multilevelRR schedule.c #include schedule.h #include / * * * Function to initialize any global variables for the scheduler. * / void init ( )

multilevelRR
schedule.c
#include "schedule.h"
#include
/**
* Function to initialize any global variables for the scheduler.
*/
void init(){
}
/**
* Function to add a process to the scheduler
* @Param process - Pointer to the process control block for the process that
* needs to be scheduled. PCB is defined in the header.
* @return true/false response for if the addition was successful
*/
int addProcess(PCB* process){
return 0;
}
/**
* Function to get the next process from the scheduler
* @Param time - pass by reference variable to store the quanta of time
* the scheduled process should run for
* @Return returns pointer to process control block that needs to be executed
* returns NULL if there is no process to be scheduled.
*/
PCB* nextProcess(int *time){
return NULL;
}
/**
* Function that returns a boolean 1 True/0 False based on if there are any
* processes still scheduled
* @Return 1 if there are processes still scheduled 0 if there are no more
* scheduled processes
*/
int hasProcess(){
return 0;
schedule.h
#ifndef _schedule_h_
#define _schedule_h_
typedef struct
{
int pid;
int priority;
} PCB;
void init();
int addProcess(PCB* process);
PCB* nextProcess(int *time);
int hasProcess();
#endif
sim.c
#include
#include
#include
#include
#include
#include
#include
#include
#include "schedule.h"
//
// main - The simulator's main routine
//
int main(int argc, char **argv){
int processes[14];
init();
int i;
for(i=0;i<10;i++){
processes[i]=100;
int priority = i%4;
printf("Scheduled Process: %d, Priority:%d
", i, priority);
PCB* proc =(PCB *) malloc(sizeof(PCB));
proc->pid = i;
proc->priority=priority;
addProcess(proc);
}
PCB* process = NULL;
int count =0;
int time =0;
while(hasProcess()){
process = nextProcess(&time);
if(!process){
printf("NULL Process, something went wrong in your code.
");
exit(1);
}
for(;time>0;time--){
printf("Process %d executed
", process->pid);
processes[process->pid]--;
if(processes[process->pid]<0){
printf("Process %d Finished
", process->pid);
}
count++;
}
if(processes[process->pid]>=0){
addProcess(process);
} else {
free(process);
}
if(count==400){
for(;i<14;i++){
processes[i]=100;
int priority = i%4;
printf("Scheduled Process: %d, Priority:%d
", i, priority);
PCB* proc =(PCB *) malloc(sizeof(PCB));
proc->pid = i;
proc->priority=priority;
addProcess(proc);
}
}
}
exit(0); //control never reaches here
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!