0% found this document useful (0 votes)
194 views

Lap No-08 - Implementation of SJF Scheduling Algorithm

The document discusses the Shortest Job First (SJF) scheduling algorithm, explaining that it selects the next process to run based on the shortest burst time, and provides a C program example that implements SJF scheduling by sorting processes by burst time and selecting the process with the minimum burst time at each step. It also notes some challenges with SJF scheduling in practice due to the difficulty of predicting process burst times precisely.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views

Lap No-08 - Implementation of SJF Scheduling Algorithm

The document discusses the Shortest Job First (SJF) scheduling algorithm, explaining that it selects the next process to run based on the shortest burst time, and provides a C program example that implements SJF scheduling by sorting processes by burst time and selecting the process with the minimum burst time at each step. It also notes some challenges with SJF scheduling in practice due to the difficulty of predicting process burst times precisely.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Report No.

08

Lab Report Name: Implementation of SJF Scheduling algorithm .

Objectives:
i. What is SJF Scheduling algorithm.
ii. How to implementation in C

Theory:
In SJF scheduling, the process with the lowest burst time, among the list of available processes in
the ready queue, is going to be scheduled next.
However, it is very difficult to predict the burst time needed for a process hence this algorithm is
very difficult to implement in the system.
It is of two types:
1.Non Pre-emptive
2.Pre-emptive

Algorithm:
➢ Sort all the process according to the arrival time.
➢ Then select that process which has minimum arrival time and minimum Burst time.
➢ After completion of process make a pool of process which after till the completion of
previous process and select that process among the pool which is having minimum Burst time.

Example:
C program for implementing for implementing shorted job first algorithms:

#include<bits/stdc++.h>
using namespace std;
main()
{
int n;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
int bt[n],p[n],wt[n],i,j,total=0,pos,temp;

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


{
printf("\nEnter Burst Time of processs %d : ",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
}
sort(bt,bt+n);

wt[0]=0;
for(i=1; i<n; i++)
{
wt[i]=0;
for(j=0; j<i; j++)
wt[i]+=bt[j];

total+=wt[i];
}

avg_wt=(float)total/(float)n;
printf("\nProcess\t Burst Time \tWaiting Time");
for(i=0; i<n; i++)
{
printf("\np%d\t\t %d\t\t %d",p[i],bt[i],wt[i]);
}
printf("\n\nAverage Waiting Time=%f",avg_wt);
return 0;
}

outputs:

You might also like