Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OPERATING SYSTEMS PPROJECT A Develop a program in C++ that will receive the foll

ID: 3833895 • Letter: O

Question

OPERATING SYSTEMS PPROJECT A Develop a program in C++ that will receive the following input from the keyboard: a. Number of processes and the corresponding arrival time and finish time for each process. b. The total number of resources, the value of resource vector, request matrix and allocation matrix. Having these information, your program should be able to show whether or not deadlock will occur. If deadlock occurs, all processes that involve in the deadlock should be listed. Assuming all processes are running in a uniprocessor environment, your program should be able to show how the processes are scheduled until completion based on two uniprocessor scheduling namely Shortest Process Next and Round Robin (Q=1). Then your program is required to calculate the turnaround time for each process and the mean of turnaround time and display which of the two algorithm is more efficient.

Explanation / Answer

//////round Robin scheduling algorithm////

#include<iostream.h>

#include<conio.h>

struct process

{

    int no;

    int at,et,wt,tt;

    int tet;

    int t;

};

void main()

{

    process p[99];

    int i,j,k;

    cout<<" Enter No of Processes:";

    int np;

    cin>>np;

    for (i=0;i<np;i++)

    {

        cout<<" Enter Execution time of process"<<i+1<<":";

        cin>>p[i].et;

        p[i].tet=p[i].et;

        p[i].at=p[i].t=p[i].tt=p[i].wt=0;

        p[i].no=i+1;

    }

    cout<<" Enter Time Quantum:";

    int q;

    cin>>q;

    cout<<" Entered Data";

    cout<<" Process ET";

    for(i=0;i<np;i++)

    {

        cout<<" "<<p[i].no<<" "<<p[i].et;

    }

    int totaltime=0;

    for(i=0;i<np;i++)

    {

        totaltime+=p[i].et;

    }

    i=0;

    k=0;

    int rrg[99];

    for(j=0;j<totaltime;j++)

    {

        if((k==0)&&(p[i].et!=0))

        {

            p[i].wt=j;

            if((p[i].t!=0))

            {

                p[i].wt-=q*p[i].t;

            }

        }

        if((p[i].et!=0)&&(k!=q))

        {

            rrg[j]=p[i].no;

            p[i].et-=1;

            k++;

        }

        else

        {

            if((k==q)&&(p[i].et!=0))

            {

                p[i].t+=1;

            }

            i=i+1;

            if(i==np)

            {

                i=0;

            }

                k=0;

            j=j-1;

        }

    }

    /*

    for(j=0;j<totaltime;j++)

    {

        cout<<" "<<rrg[j];

    }

    */

    int twt=0;

    int ttt=0;

    cout<<" Result Of Round Robin";

    cout<<" PNo ET WT TT";

    for(i=0;i<np;i++)

    {

        p[i].tt=p[i].wt+p[i].tet;

        ttt+=p[i].tt;

        twt+=p[i].wt;

        cout<<" "<<p[i].no<<" "<<" "<<p[i].tet<<" "<<p[i].wt<<" "<<p[i].tt;

    }

    cout<<" Average Waiting Time:"<<(float)twt/np;

    cout<<" Average Turn Around Time:"<<(float)ttt/np;

    getch();

}

Expected output:

Enter No of Processes:5

Enter Execution time of process1:10

Enter Execution time of process2:29

Enter Execution time of process3:3

Enter Execution time of process4:7

Enter Execution time of process5:12

Enter Time Quantum:10

Entered Data

Process        ET

1      10

2      29

3      3

4      7

5      12

Result Of Round Robin

PNo    ET      WT      TT

1              10      0       10

2              29      32      61

3              3       20      23

4              7       23      30

5              12      40      52

Average Waiting Time:23

Average Turn Around Time:35.2