Operating System - Lab Manual # 8
Operating System - Lab Manual # 8
LAB MANUAL # 8
(SPRING 2023)
Objective(s) :
To write a C program to implement CPU scheduling algorithm for Priority
Scheduling.
Lab Tasks :
Task 01: Calculate the Average Time using Priority Scheduling.
Total 40 Signature
Note : Attempt all tasks and get them checked by your Instructor
Objective(s):
To write a C program to implement CPU scheduling algorithm for Priority Scheduling.
Tool(s) used:
CPU scheduler will decide which process should be given the CPU for its execution. For this it use
different algorithm to choose among the process. One among that algorithm is FCFS algorithm. In this
algorithm the process which arrives first is given the CPU after finishing its request only it will allow
CPU to execute other process. In priority scheduling algorithm each process has a priority associated
with it and as each process hits the queue, it is stored in based on its priority so that process with higher
priority are dealt with first. It should be noted that equal priority processes are scheduled in FCFS order.
P1 9 5
P2 4 3
P3 5 1
P4 7 2
P5 3 4
Total 28
#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);
printf("\nEnter Burst Time and Priority\n");
for(i=0;i<n;i++)
{
printf("\nP[%d]\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1; //contains process number
}
//sorting burst time, priority and process number in ascending order
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;
}
return 0;
}
OUTPUT