Skip to main content

ROUND ROBIN SCHEDULING ALGORITHM

Round-robin (RR) is one of the algorithms employed by process and network schedulers in computing. As the term is generally used, time slices are assigned to each process in equal portions and in circular order, handling all processes without priority (also known as cyclic executive). Round-robin scheduling is simple, easy to implement, and starvation-free. Round-robin scheduling can also be applied to other scheduling problems, such as data packet scheduling in computer networks. It is an Operating System concept.
The name of the algorithm comes from the round-robin principle known from other fields, where each person takes an equal share of something in turn.

/* IMPLEMENTATION OF ROUND ROBIN SCHEDULING ALGORITHM


AIM

To write a c program to implement the round robin scheduling algorithm

ALGORITHM

1. Start the process

2. Declare the array size

3. Get the number of elements to be inserted

4. Get the value

5. Set the time sharing system with preemption

6. Define quantum is defined from 10 to 100ms

7. Declare the queue as a circular

8. Make the CPU scheduler goes around the ready queue allocating CPU to each process
    for the time interval specified

9. Make the CPU scheduler picks the first process and sets time to interrupt after quantum
    expired dispatches the process

9. If the process have burst less than the time quantum than the process release the CPU

10. If the process have bust greater then time quantum then time will go off and cause
      interrupt to OS and the process put into the tail of ready queue and the schedule select
      next process

11. Display the results

12. Stop the process

*/
PROGRAM:
#include<stdio.h>
int ttime,i,j,temp;
main()
{
        int pname[10],btime[10],pname2[10],btime2[10];
        int n,x,z;
        printf("Enter the no. of process:");
        scanf("%d",&n);
        printf("Enter the process name and burst time for the process\n");
        for(i=0;i<n;i++)
        {    
    printf("Enter the process name:");
                scanf("%d",&pname2[i]);
                printf("Enter burst time for the process %d:",pname2[i]);
                scanf("%d",&btime2[i]);
        }
        printf("PROCESS NAME \t\t BURST TIME\n");
        for(i=0;i<n;i++)
            printf("%d\t\t\t %d\n",pname2[i],btime2[i]);
            z=1;
        while(z==1)
        {
ttime=0;
        for(i=0;i<n;i++)
        {
pname[i]=pname2[i];
            btime[i]=btime2[i];
        }

            printf ("PRESS 1.ROUND ROBIN 2.EXIT\n");
            scanf("%d",&x);
        switch(x)
        {
        case 1:
                rrobin(pname,btime,n);
                break;
        case 2:
                exit(0);
                break;
        default:
                printf("Invalid option");
               break;
       }
       printf("\n\n If you want to continue press 1:");
       scanf("%d",&z);
       }
}
   
 rrobin(int pname[],int btime[],int n)
       {
            int tslice;
            j=0;
            printf("\n\t ROUND ROBIN SCHEDULING \n\n");
            printf("Enter the time slice:\n");
            scanf("%d",&tslice);
            printf("PROCESS NAME \t REMAINING TIME\t TOTAL TIME");
   

while(j<n)
            {
      for(i=0;i<n;i++)
{
      if(btime[i]>0)
                        {
if(btime[i]>=tslice)
                                    {
ttime+=tslice;
                                                btime[i]=btime[i]-tslice;
                                                printf("\n%d\t\t %d \t\t %d",pname[i],btime[i],ttime);
                                                if(btime[i]==0)
                                                 j++;
                                    }
                                    else
                                    {
ttime+=btime[i];
                                                btime[i]=0;
                                                printf("\n%d\t\t %d \t\t %d",pname[i],btime[i],ttime);
                                    }
}
 }
       }
}

/*
OUTPUT:

Enter the no. of process: 4
Enter the process name and burst time for the process
Enteer the process name: 1
Enter burst time for the process 1: 8
Enteer the process name: 2
Enter burst time for the process 2: 3
Enteer the process name: 3
Enter burst time for the process 3: 6
Enteer the process name: 4
Enter burst time for the process 4: 1

PROCESS NAME             BURST TIME
             1                                         8
             2                                         3
             3                                         6
             4                                         1

PRESS 1.ROUND ROBIN 2.EXIT
1
ROUND ROBIN SCHEDULING

Enter the time slice:
2
PROCESS NAME     REMAINING TIME  TOTAL TIME
1                                     6                                2
2                                     1                                4
3                                     4                                6
4                                     0                                7
1                                     4                                9
2                                     0                                10
3                                     2                                12
1                                     2                                14
3                                     0                                16                                 */

Comments

Popular posts from this blog

Login and Registration Example in JSP with Session

Those who want to start with jsp and MySQL, this is an excellent example for themselves. Here you can learn how to insert data to MySQL using JSP. Also you can learn about session handling in jsp. 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `members` (    `id` int (10) unsigned NOT NULL auto_increment,    `first_name` varchar (45) NOT NULL ,    `last_name` varchar (45) NOT NULL ,    `email` varchar (45) NOT NULL ,    `uname` varchar (45) NOT NULL ,    `pass` varchar (45) NOT NULL ,    `regdate` date NOT NULL ,    PRIMARY KEY   (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; index.jsp 1 2 3 4 5 6 ...

Timer funcitons in JavaScript: Reminder Script

Timers are used in web pages and we will discuss how to setup one and how to use one with an example. The function setTimeout() in function is used and here is its general syntax. mytime = setTimeout(expression, msec); mytime  is the identifier used to identify the current timeout function.  expression  is the statement that is to be executed after the specified time has ticked off.  msec  is the duration of time in milliseconds after which the expression will be executed.  You can see by using setTimeout function we can execute any function or object after a set of time. For example if msec is set 5000 then the expression will be executed after 5 seconds or 5000 milliseconds.  We will try one example where we will have four period buttons and each button will set a different time for another function to execute and display a alert button. We will call it as a reminder script and we will get one alert box based on the period button we click...

Binary Addition

/* File Name : BinAdd.java */    import java.util.*; public class BinAdd    {  public static String addBit(String a, String b, String c)  { String r=""; if(a.equals("1") && b.equals("0") || a.equals("0") && b.equals("1")) { if( c.equals("0")) r="1"; else { r="0"; c="1"; } } else if( a.equals("0") && b.equals("0") ) { if(c.equals("0")) r="0"; else r="1"; } else if( a.equals("1") && b.equals("1") ) { if(c.equals("0")){ r="0"; c="1"; } else { r="1"; c="1"; } } return c+r; }   public static String add(String a, String b)   { String r=""; int len=a.length(); String carry="0"; for(int i=len-1;i...

Real time changing Clock showing date and time

We can display a clock which will be showing the local time of the client computer by using JavaScript. Note that this time displayed is taken from user computer and not from the server.  We have seen in our  date object example how to display current date and time   where the current date and time is displayed once. Here we will try to display changing clock or real time change in date and time by using  setTimeout function . This setTimeout function we have used to trigger the time display function in a refresh rate of 1000 mill seconds ( 1 Sec ). This refresh rate can be changed to any other value. By changing the value to 5000 the clock will refresh and show the exact time once in every 5 seconds.  Here is the demo of this script and code is given below that.  Sat Apr 23 2016 08:27:22 GMT+0530 (IST)   Here is the code <html> <head> <title>(Type a title for your page here)</title> <script type="text/javascript...