Expt No. 5
Expt No. 5
#include <stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat; printf("Enter
Total Number of Process:");
scanf("%d",&n);
//sorting burst time, priority and process number in ascending order using selection sort for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
}
Preemptive Scheduling:
Preemptive scheduling is used when a process switches from running state to ready state or from the waiting
state to ready state. The resources (mainly CPU cycles) are allocated to the process for a limited amount of
time and then taken away, and the process is again placed back in the ready queue if that process still has
CPU burst time remaining. That process stays in the ready queue till it gets its next chance to
execute.Algorithms based on preemptive scheduling are Round Robin Shortest Remaining Time
first(SRTF),Priority
ROUND ROBIN SCHEDULING ALGORITHM We first have a queue where the processes are
arranged in first come first serve order. A quantum value is allocated to execute each process.
The first process is executed until the end of the quantum value. After this, an interrupt is generated
and the state is saved.
The CPU then moves to the next process and the same method is followed. Same steps
are repeated till all the processes are over.
ADVANTAGES:
Low overhead for decision making.
Unlike other algorithms, it gives equal priority to all processes.
Starvation rarely occurs in this process.
DISADVANTAGES:
The efficiency of the system is decreased if the quantum value is low as frequent switching takes
place.
The system may become unresponsive if the quantum value is high.
How to compute below times in Round Robin using a program?
int main()
{
int i, limit, total = 0, x, counter = 0, time_quantum;
int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10]; float
average_wait_time, average_turnaround_time;
printf("Enter Total Number of Processes:");
scanf("%d", &limit);
x = limit;
for(i = 0; i < limit; i++)
{
printf("Enter Details of Process[%d]\t", i + 1);
printf("Arrival Time:\t");
scanf("%d", &arrival_time[i]);
printf("Burst Time:\t");
scanf("%d", &burst_time[i]);
temp[i] = burst_time[i];
}
OP:
Conclusion:- Hence we hve studied the concept of non-preemptive and Preemptive Scheduling
Algorithm.Scheduling Algorithm and successfully.
SIGN GRADEDATE