Вы находитесь на странице: 1из 10

Operating - System

Simulation Based Project Report

Project title: Write and Implement the algorithm


To schedule ten students for priority wise and compute
average waiting time ,turnaround time Consider burst time
and priority is given by user.

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.

• A priority number (integer) is associated with each process


• The CPU is allocated to the process with the highest priority
• Equal priority processes are treated in FCFS manner.
• No general agreement whether 0 is highest or lowest priority.
• But in this we assume; (smallest integer  highest priority)
• Priorities can be defined internally or externally.
• Internally defined priorities use some measurable quantities. Eg
time limits, memory requirements, number of open files etc.
• Externally: importance of the process and other political factors.
• Supports both preemptive and non-preemptive
• Preemptive will preempt the CPU if priority of newly arrived
process is higher than the currently running process.
• Non-preemptive
• SJF is a priority scheduling where priority is the predicted
according to the shortest CPU burst time

Advantages of priority scheduling:-


 It is a process of simplicity
 Reasonable support for priority
 Suitable for application with varying time and resource
requirements

Disadvantages of priority Scheduling:-


 Indefinite blocking or starvation
 A priority scheduling can leave some low priority waiting
process indefinitely for CPU
 If the system eventually crashes then all unfinished low priority
Priority process gets lost.
 If there are many works so priority scheduling do first high
priority works, then will do low priority works.

Question: Ten students (a,b,c,d,e,f,g,h,i,j) are going to get there


pictured clicked by university camera. Only one student
can enter the camera room while the other students wait outside the
room. The students are waiting in a queue to
enter the room. To pass time the students start to play a game. In
this game the students give candies to each other in
a random manner (assume the students never run out of candies).
They decide that the student with highest candies
will be allowed to enter. When the student with highest amount of
candies enter the room, the student starts the
game again. Initially the students do not know if there is any body in
the room and they start their game and the
student with highest candies enter. Write and implement the
algorithm to schedule such and compute the waiting
and turnaround time. Consider the arrival time and burst time as
given by the user.

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:

Вам также может понравиться