Академический Документы
Профессиональный Документы
Культура Документы
Submitted to:
Ms. Maneet kaur
Submitted by:
Name: Vikas Raria
Sec: K17PJ
Roll no:51
Objectives
Basically this project is based on priority scheduling
algorithm where highest priority process is executed first and
so on and where user enter the number of process and their
burst time and priority and after that calculating average
waiting time and turnaround time.
INTRODUCTION
CPU scheduling is the basis of multiprogramming.
Scheduling Algorithm optimization criteria:-
• CPU utilization – keep the CPU as busy as possible
• Max CPU utilization
• Throughput – # of processes that complete their execution per
time unit
• Max throughput
• Turnaround time – amount of time to execute a particular
process
• Min turnaround time
• Turnaround time= Completion Time- Arrival Time
• Waiting time – amount of time a process has been waiting in
the ready queue
• Min waiting time
• Waiting Time= Turnaround Time-Burst Time
• Response time – amount of time it takes from when a request
was submitted until the first response is produced, not output
(for time-sharing environment).
• Min response time
Priority Scheduling
Definition - What does Priority
Scheduling mean?
Priority scheduling is a method of scheduling processes
based on priority. In this method, the scheduler chooses
the tasks to work as per the priority, which is different
from other types of scheduling, for example, a simple
round robin.
Priority scheduling involves priority assignment to every
process, and processes with higher priorities are carried
out first, whereas tasks with equal priorities are carried
out on a first-come-first-served (FCFS) or round robin
basis. An example of a general-priority-scheduling
algorithm is the shortest-job-first (SJF) algorithm.
CODE:
#include<stdio.h>
int main()
{
int bt[20], student[20], wt[20], tat[20], candies[20];
int i, j, n, sum = 0, p, temp;
float avg_wt, average_tat;
printf("Enter Total Number of studentes:\t");
scanf("%d", &n);
printf("\nEnter Time inside the room and candies For %d
studentes\n", n);
for(i = 0; i < n; i++)
{
printf("\nstudent[%d]\n", i + 1);
printf("Time inside room:\t");
scanf("%d", &bt[i]);
printf("Number of candies with Student\t");
scanf("%d", &candies[i]);
student[i] = i + 1;
}
for(i = 0; i < n; i++)
{
p = i;
for(j = i + 1; j < n; j++)
{
if(candies[j] > candies[p])
{
p = j;
}
}
temp = candies[i];
candies[i] = candies[p];
candies[p] = temp;
temp = bt[i];
bt[i] = bt[p];
bt[p] = temp;
temp = student[i];
student[i] = student[p];
student[p] = temp;
}
wt[0] = 0;
for(i = 1; i < n; i++)
{
wt[i] = 0;
for(j = 0; j < i; j++)
{
wt[i] = wt[i] + bt[j];
}
sum = sum + wt[i];
}
avg_wt = sum / n;
sum = 0;
printf("\nStudent ID\t\tBurst Time\t Waiting Time\t
Turnaround Time \t candies\n");
for(i = 0; i < n; i++)
{
tat[i] = bt[i] + wt[i];
sum = sum + tat[i];
printf("\nStudent[%d]\t\t%d\t\t\t %d\t\t %d\t\t\t
%d\n", Student[i], bt[i], wt[i], tat[i],candies[i]);
}
average_tat = sum / n;
printf("\nAverage Waiting Time:\t%f", avg_wt);
printf("\nAverage Turnaround Time:\t%f\n", average_tat);
return 0;
}
Output: