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

Submitted To:: Software Engineering Department (Sed)

The document is a lab report submitted by Muhammad Yasir Hassan to Ma'am Rabia Arshad. It implements the Shortest Job First (non-preemptive) CPU scheduling algorithm. The program takes input of the number of processes and their burst times, sorts the burst times in ascending order, calculates the waiting times and turnaround times of each process, and outputs the average waiting and turnaround times.
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)
20 views3 pages

Submitted To:: Software Engineering Department (Sed)

The document is a lab report submitted by Muhammad Yasir Hassan to Ma'am Rabia Arshad. It implements the Shortest Job First (non-preemptive) CPU scheduling algorithm. The program takes input of the number of processes and their burst times, sorts the burst times in ascending order, calculates the waiting times and turnaround times of each process, and outputs the average waiting and turnaround times.
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

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

SOFTWARE ENGINEERING DEPARTMENT (SED)

Lab #11

SUBMITTED TO:

Ma’am Rabia Arshad

SUBMITTED BY:

Muhammad Yasir Hassan

ROLL NUMBER:

19-SE-31

SECTION:

Alpha (α)

DATE:

12-01-2022
Lab Task
Task 1:
Implement Shortest Job First (Non-Preemptive) CPU Scheduling Algorithm.
#include<stdio.h>
void main()
{
int burst_time[20],p[20],waiting_time[20],turnaround_time[20],i,j,n,total = 0,pos,temp;
float avg_waiting_time,avg_turnaround_time;
printf("\n Enter the Number of Processes: ");
scanf(" %d",&n);
printf("\n\t\t\t\t ---> Burst Time ---> \n");
for(i=0;i<n;i++)
{
printf(" Process %d: ",i+1);
scanf("%d",&burst_time[i]);
p[i] = i+1;
}
//Sorting Burst Time in Ascending Order using Selection Sort
for(i=0;i<n;i++)
{
pos = i;
for(j=i+1;j<n;j++)
{
if(burst_time[j]<burst_time[pos])
pos = j;
}
temp = burst_time[i];
burst_time[i] = burst_time[pos];
burst_time[pos] = temp;
temp = p[i];
p[i] = p[pos];
p[pos] = temp;
}
waiting_time[0] = 0; //Waiting Time for First Process will be Zero

//Calculate Waiting Time


for(i=1;i<n;i++)
{
waiting_time[i] = 0;
for(j=0;j<i;j++)
waiting_time[i] += burst_time[j];
total += waiting_time[i];
}
avg_waiting_time = (float)total/n; //Average Waiting Time
total = 0;
printf("\n Processes \t Burst Time \t Waiting Time \t\t Turnaround Time");
for(i=0;i<n;i++)
{
turnaround_time[i] = burst_time[i] + waiting_time[i]; //Calculate Turnaround Time
total += turnaround_time[i];
printf("\n Process %d\t\t %d \t\t %d \t\t\t %d
",p[i],burst_time[i],waiting_time[i],turnaround_time[i]);
}
avg_turnaround_time = (float)total/n; //Average Turnaround Time
printf("\n\n Average Waiting Time: %f",avg_waiting_time);
printf("\n Average Turnaround Time: %f\n",avg_turnaround_time);
}

You might also like