Hi there, i am writting a process scheduler in a round robin fashion and I want to process all the processes from a input file. I have got all the processes from the file and ordered the priority using qsort with 0 as the highest priority and 20 as the lowest.
I want to know how I can alter my loops so that it processes all the priority members that have a value of 0 first then the 1's thens 2's etc. I can roughly think of one way which may be a bit lengthily, which I don't mind as long as it gets the job done, but as a newbie to C I need help implementing it.
The file layout is like so:
ProcessID Quantum Priority
Process0 50 18
Process1 3 3
Process2 99 0
Using this code here does execute all the processes but only decrements the quantum from the 0's to 20's once each time it passes through the loop. But I want all the 0 priorities quantum to reach 0 and then move onto the next highest priority which is 1 ...Code:/* order process priority from 0 to 20 */ qsort(proc, num_procs, sizeof(*proc), comp); bool needToContinue = 1; //keep processing until all have been processed (ie all quanta == 0) while(needToContinue) { //reset the flag each loop of the array needToContinue = false; //loop thru the entire array for(num_procs=0;num_procs<199;++num_procs)//loop through the array { //check to see if this element is finished if(proc[num_procs].quantum > 0) //not finished so process { proc[num_procs].state = WORKING; if ( proc[num_procs].state == WORKING ) //Process being executed ... { proc[num_procs].quantum--; printf("%s %d %d \n",proc[num_procs].id, proc[num_procs].quantum, proc[num_procs].priority); } } } //now check to see if we have finished processing this element //or need to keep going next loop if(proc[num_procs].quantum > 0) { //we found an element that will need to be processed in the next loop, //so set the flag to continue looping needToContinue = true; } } //show processing is finished
I was thinking something along the lines of :
Thanks for any feedbackCode:while ( proc[num_procs].priority == 0) { The Code Above to be in here printf("End of Process Scheduling\n");