round robin scheduling algorithm

Feb 28, 2012 at 7:17pm
Hey guys. I am working on an assignment that will emulate cpu scheduling algorithms with an array of structs of process information. Right now I have FirstComeFirstServe completed and i'm working on round robin. Here is the FCFS code: http://pastebin.com/9MihwuPY

I have found some code on the web of the round robin algorithm, but the person has written it using different types of data structures, and I'm having a hard time converting it to use with my structs. Maybe you guys can give me some help? I have part of it completed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void RR15(Process P[])
{
        int q = 15; //q is the time quantum
        int sp = 0; //time spent
        int i, k, time, j = 0;
        Process temp[50];
        bool f = false; //flag to indicate whether any process
                        //was scheduled as i changed from 0 n-1
                        //in the next for loop

        //while there are uncompleted processes
        for(i=0; j < 50; i=(i+1)%50)
        {
                //find the next uncompleted processes which has already
                //or just arived
                if(P[i].CPU_Burst>0 && sp>=P[i].Arrival_Time)
                {
                        f=true;
                        //if process requests for time less than quantum
                        if(P[i].CPU_Time <= q)
                                time = P[i].CPU_Burst;
                        else
                                time = q;

                        //schedule the process
                        P[i].Turn_Time += time, P[i].CPU_Burst....?
}


And here's the code I have been basing it off of (code I've been following is in the calc() function): http://pastebin.com/tNYkxedF

Can anyone look at my code and tell me if what I have so far seems correct? or what I do next? I got stuck at the //schedule the process .
Last edited on Feb 28, 2012 at 7:18pm
Feb 28, 2012 at 7:25pm
EDIT: this is solved.
Last edited on Feb 29, 2012 at 11:56pm
Topic archived. No new replies allowed.