Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is part of a simple Round Robin Scheduler I am working on for an OS assignment. It begins scheduling the processes correctly, but towards

This is part of a simple Round Robin Scheduler I am working on for an OS assignment. It begins scheduling the processes correctly, but towards the end does not match the desired output. Can someone point out the flaw in my logic without giving too much away? Thank you

#include "schedule.h"

#include

#include

/**

* Function to initialize any global variables for the scheduler.

*/

struct node{

PCB* proc;

struct node* next;

};

struct node* root;

struct node* cur;

void init(){

root=NULL;

cur = root;

}

/**

* 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){

if(root==NULL){

root = (struct node*) malloc( sizeof(struct node));

cur = root;

}

else{

cur->next = (struct node*) malloc( sizeof(struct node));

cur = cur->next;

}

cur->proc = 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){

cur=root;

*time=4;

if(cur!=NULL){

PCB* temp_proc;

temp_proc=cur->proc;

cur=root;

if(root->next!=NULL)

root=root->next;

else

root=NULL;

free(cur);

return temp_proc;

}

else

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(){

if(root==NULL)

return 0;

else

return 1;

}

//----------------second file w/ main func--------------

#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[10]; init(); int i; for(i=0;i<10;i++){ processes[i]=100; printf("Scheduled Process: %d ", i); PCB* proc = (PCB *) malloc(sizeof(PCB)); proc->pid = i; proc->priority=0; addProcess(proc); }

PCB* process = NULL; 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); break; } } if(processes[process->pid]>=0){ addProcess(process); } }

exit(0); //control never reaches here }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago