Documente Academic
Documente Profesional
Documente Cultură
Name: J Ruthvik
Roll no:136
Reg num:11608066
Submitted to: Mr. Parminder Singh
INTRODUCTION:
Shortest Job First(SJF) Scheduling:
Shortest Job First scheduling works on the process with the shortest burst
time or duration first.
It is of two types:
1. Non Pre-emptive
2. Pre-emptive
To successfully implement it, the burst time/duration time of the processes should
be known to the processor in advance, which is practically not feasible all the time.
This scheduling algorithm is optimal if all the jobs/processes are available at the
same time. (either Arrival time is 0 for all, or Arrival time is same for all.
the We scheduled the same set of processes using the First come first serve algorithm in previous
tutorial, and got average waiting time to be 18.75 ms, whereas with SJF, the average waiting time
comes out 4.5 ms.
Question:
5. Consider a scheduling approach which is non pre-emptive similar to
shortest job next in nature. The priority of each job is dependent on its
estimated run time, and also the amount of time it has spent waiting. Jobs
gain higher priority the longer they wait, which prevents indefinite
postponement. The jobs that have spent a long time waiting compete
against those estimated to have short run times. The priority can be
computed as :
=1+
Using the data given below compute the waiting time and turnaround time
for each process and average waiting time and average turnaround time.
Process Arrival time
P1 0
P2 5
P3 13
P4 17
Program:
#include<stdio.h>
struct process
{
char name;
int at,bt,ct,wt,tt,priority;
int processed;
}p[10];
int n;
void sortByCandies()
{
struct process temp;
int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if(p[i].priority<p[j].priority)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
int main()
{
int i,j,time=0,sum_bt=0,largest;
char c;
float avgwt=0;
printf("Enter no of Students:");
scanf("%d",&n);
for(i=0,c='A';i<n;i++,c++)
{
p[i].name=c;
printf("\nEnter the arrival time , burst time, candies for each
student %c: ",p[i].name);
scanf("%d%d%d",&p[i].at,&p[i].bt,&p[i].priority);
p[i].processed=0;
sum_bt+=p[i].bt;
}
sortByCandies();