7. C Program: Preemptive SJF Scheduling (WT, TAT, AWT)

 #include <stdio.h>


int main() {

    int arrival_time[10], burst_time[10], temp[10];

    int i, smallest, count = 0, time, limit;

    double wait_time = 0, turn_around_time = 0, end;

    float average_waiting_time, average_turn_around_time;


    printf("\nEnter total number of processes: ");

    scanf("%d", &limit);

    

    printf("\nEnter details of %d processes\n", limit);

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

        printf("\nEnter Arrival Time: ");

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

        printf("Enter Burst Time: ");

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

        temp[i] = burst_time[i];

    }


    burst_time[9] = 9999;


    for(time = 0; count != limit; time++) {

        smallest = 9;

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

            if(arrival_time[i] <= time && burst_time[i] > 0 && burst_time[i] < burst_time[smallest]) {

                smallest = i;

            }

        }


        burst_time[smallest]--;


        if(burst_time[smallest] == 0) {

            count++;

            end = time + 1;

            wait_time += end - arrival_time[smallest] - temp[smallest];

            turn_around_time += end - arrival_time[smallest];

        }

    }


    average_waiting_time = wait_time / limit;

    average_turn_around_time = turn_around_time / limit;


    printf("\n\nAverage Waiting Time:\t%.2f", average_waiting_time);

    printf("\nAverage Turn Around Time:\t%.2f\n", average_turn_around_time);


    return 0;

}

Comments

Popular posts from this blog

6. Write a program to calculates Waiting Time (WT), Turnaround Time (TAT), Average WT, and Average TAT using the FCFS (First Come First Serve) scheduling algorithm.

8. To write a program in C to calculate waiting time, turn around time and average waiting time when non preemptive SJF is used