0% found this document useful (0 votes)
53 views3 pages

OS Lab 2 SJF PDF

The document describes the Shortest Job First (non-preemptive) CPU scheduling algorithm. It explains that the algorithm sorts processes by burst time from shortest to longest. It then calculates the waiting time of each process as the sum of the burst times of the preceding processes. The algorithm calculates the average waiting time and average turnaround time. Source code in C is provided to implement the Shortest Job First scheduling algorithm.

Uploaded by

kwer
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)
53 views3 pages

OS Lab 2 SJF PDF

The document describes the Shortest Job First (non-preemptive) CPU scheduling algorithm. It explains that the algorithm sorts processes by burst time from shortest to longest. It then calculates the waiting time of each process as the sum of the burst times of the preceding processes. The algorithm calculates the average waiting time and average turnaround time. Source code in C is provided to implement the Shortest Job First scheduling algorithm.

Uploaded by

kwer
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

B.

SHORTEST JOB FIRST:


AIM: To write a program to stimulate the CPU scheduling algorithm Shortest job first (Non-
Preemption)
DESCRIPTION:
To calculate the average waiting time in the shorting job first algorithm the sorting of the
process based on their burst time in ascending order the calculate the waiting time of each
process as the sum of the bursting time of all the process previous or before to that process.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to
highest burst time
Step 5: Set the waiting time of the first process as _0' and its turnaround time as its burst time
Step 6: Sort the processes names based on their burst time
Step 7: For each process in the ready queue, calculate
A) Waiting time (n) =waiting time (n-1) +burst time (n-1)
B) Turnaround time (n) =waiting time (n) +burst time (n)
Step 8: Calculate
C) Average waiting time=total waiting time/number of process
D) Average Turnaround =total turnaround time/number of process
Step 9: Stop the process.
Source code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int p[20],bt[20], wt[20],tat[20],i,k,n,temp;
float wtavg,tatavg;
clrscr();
printf("\n enter the number of process--");
scanf("%d",&n);
for(i=0; i<n;i++)
{
p[i]=i;
printf("enter burst time for process%d--",i);
scanf("%d", &bt[i]);
}
for(i=0; i<n; i++)
for(k=i+1; k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
wt[0]=wtavg=0;
tat[0]=tatavg=bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=tat[i-1]+bt[i];
wtavg=wtavg+wt[i];
tatavg=tatavg+tat[i];
}
printf("\n\t process\tburst time\t waiting time\t turnaround time\n");
for(i=0;i<n;i++)
printf("\n\t p%d\t\t%d\t\t%d\t\t%d",p[i],bt[i],wt[i],tat[i]);
printf("\n average waiting time--%f", wtavg/n);
printf("\n average turnaround time--%f", tatavg/n);
getch();
}
Output:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy