ROUND ROBIN SCHEDULING:
    Round-robin (RR) is one of the simplest scheduling algorithms for processes in an operating system, which assigns time slices to each process in equal portions and in circular order, handling all processes without priority. Round-robin scheduling is both simple and 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.

PROCESS SCHEDULING:
    Round-robin job scheduling may not be desirable if the sizes of the jobs or tasks are highly variable. A process that produces large jobs would be favoured over other processes. This problem may be solved by time-sharing, i.e. by giving each job a time slot or quantum (its allowance of CPU time), and interrupt the job if it is not completed by then. The job is resumed next time a time slot is assigned to that process.
A Simple CPP program to implement Round Robin Scheduling.




#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
    clrscr();
    int e_time[15],time,n,count=0;    //variable declaration
    char p_name[15];    //variable declaration
    cout<<endl<<"Enter the number of processes:";
    cin>>n;
    cout<<endl<<"Enter the time slice:";
    cin>>time;
    cout<<endl<<"Enter the process names:";
    for(int i=0;i<n;i++)    //This loop reads the process names
        cin>>p_name[i];
    cout<<endl<<"Enter the process execution time:";
    for(i=0;i<n;i++)    //This loop reads the execution time of the process
        cin>>e_time[i];
    if(n<0)
        cout<<endl<<"Invalid input";
    for(i=0;i<n;i++)    //This loop checks whether the given input is valid or not
    {
        if(e_time[i]<0)
        {
            cout<<endl<<"Invalid execution time";
            getch();
            exit(0);
        }
    }
    count=e_time[0];
    for(i=0;i<n;i++)    //The count variable in this loop finds the largest execution time
    {
        if(count<e_time[i])
            count=e_time[i];
    }
    for(i=0;i<count;i=i+time)    //This loop executes the order of the process names
    {
        for(int j=0;j<n;j++)
        {
            if(i<=e_time[j])
            {
                if(e_time[j]!=0 && e_time[j]>0)
                    cout<<p_name[j];
            }
            else if(e_time[j]<=time && e_time[j]>0)
            {
                cout<<p_name[j];
            }
            else if(e_time[j]>time)
            {
                if(e_time[j]!=0 && e_time[j]>0)
                    cout<<p_name[j];
            }
            e_time[j]=e_time[j]-time;
        }
    }
    getch();
}




0 comments: