Process Job Scheduling using Round Robin CPU scheduling policy | Operating System Lab | C Programming , - IndianTechnoEra
Latest update Android YouTube

Process Job Scheduling using Round Robin CPU scheduling policy | Operating System Lab | C Programming ,

Process Job Scheduling using Round Robin CPU scheduling policy | Operating System Lab | C Programming , DAA,Operating System,C Programming,Round Robin
Admin

 Aim: List of processes / jobs along with their arrival times & CPU burst times is given. Write a program to print the total waiting time, average waiting time, total turnaround time, average turnaround time & Gantt Chart using Round Robin CPU scheduling policy. 

Source Code:

#include <stdio.h>

int main()

{

    int i, limit, total = 0, x, counter = 0, time_quantum;

    int wt = 0, tat = 0, arrival_time[10], burst_time[10], temp[10];

    float avr_wt, avr_tat;

    printf("\nEnter number of process:");

    scanf("%d", &limit);

    x = limit;

    printf("\nEnter Details of Process\n");

    printf("Process\t Arrival Time\t Burst Time\n");

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

    {

        printf("Process %d : ", i + 1);

        scanf("%d", &arrival_time[i]);

        scanf("%d", &burst_time[i]);

        temp[i] = burst_time[i];

    }

 

    printf("\nEnter Time Quantum:\t");

    scanf("%d", &time_quantum);

    printf("\nProcess ID\tBurst Time\t Turnaround Time\t Waiting Time\n");

 

    for (total = 0, i = 0; x != 0;)

    {

        if (temp[i] <= time_quantum && temp[i] > 0)

        {

            total = total + temp[i];

            temp[i] = 0;

            counter = 1;

        }

        else if (temp[i] > 0)

        {

            temp[i] = temp[i] - time_quantum;

 

            total = total + time_quantum;

        }

        if (temp[i] == 0 && counter == 1)

        {

            x--;

 

            int tatime=total - arrival_time[i];

            int wtime=total - arrival_time[i] - burst_time[i];

            printf("Process %d \t%d\t\t %d\t\t %d \n", i + 1, burst_time[i], tatime, wtime);

            wt = wt + total - arrival_time[i] - burst_time[i];

            tat = tat + total - arrival_time[i];

            counter = 0;

        }

        if (i == limit - 1)

        {

            i = 0;

        }

        else if (arrival_time[i + 1] <= total)

        {

            i++;

        }

        else

        {

            i = 0;

        }

    }

    avr_wt = wt * 1.0 / limit;

    avr_tat = tat * 1.0 / limit;

    printf("\nAverage Waiting Time:\t%f", avr_wt);

    printf("\nnAverage Turnaround Time:\t%f\n", avr_tat);

    return 0;

}

Output:


Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.