Professional Documents
Culture Documents
Os Final Project
Os Final Project
DECLARATION
I/We hereby declare that the project entitled “HYBRID CPU
SCHEDULING
ALGORITHM” submitted by me/us to the School of Computer Science
and
Engineering, VIT University, Vellore-14 in partial fulfillment of the
requirements for the award of the degree of Bachelor of Technology in
Computer Science and
Engineering is a record of bonafide work carried out by me/us under
the
SUBMITTED BY
K.SANJEETH - 18BCI0156
L.P SAMPATH - 18BCI0234
School of Computer Science and Engineering
CERTIFICATE
ACKNOWLEDGEMENT
We would like to express our deepest appreciation to all those who provided
us the possibility to complete this report. A special gratitude we give to our
project manager, Prof. . MANIKANDAN K, whose contribution in
stimulating suggestions and encouragement, helped us to coordinate our
project especially in writing this report.
CONTENTS
• ABSTRACT
• INTRODUCTION
• OUTPUT(SCREENSHOTS)
• REFERENCES
ABSTRACT
The essential and important aspect of operating system is
multiprogramming. Multiprogramming is a process or method of executing
multiple processes simultaneously in the memory. Its main aim to minimize
the average waiting time, average turnaround time and maximize the CPU
utilization. There are various CPU scheduling algorithms are used to
performed multiprogramming like First Come First Serve (FCFS), Shortest
Job First (SJF), Priority Scheduling (PS) and Round Robin (RR). The most
widely used scheduling algorithm is Round robin scheduling among all of
them. It is an optimal CPU scheduling algorithm in timeshared systems. In
round robin algorithm the time quantum is static, and the performance of
these algorithms is totally depending upon the selection of time quantum.
This static time quantum decreases the performance of CPU scheduling like
Average waiting time, average turnaround time and CPU utilization. This
algorithm inherits the nature of both SJF and round robin algorithm
therefore it is a Hybrid Algorithm. The objective of this project is to
propose a new CPU scheduling algorithm which will perform better than the
simple Round Robin in terms of minimizing average waiting time, average
turnaround time and number of context switches.
INTRODUCTION: -
In a single-processor system, processor can run only one process at a time
and other processes must wait until the CPU is free and these processes can
be rescheduled again. The objective of multiprogramming is to run multiple
processes at a time and to maximize the uses of CPU. Scheduling is a
fundamental operating- system function. Almost all computer resources are
scheduled before use. The CPU is, of course, one of the primary computer
resources. Thus, its scheduling is central to operating-system design. CPU
scheduling determines which processes run when there are multiple run-able
processes.
This project deals with the simulation of CPU scheduling algorithms with C.
The metrics such as finishing time, waiting time, total time taken for the
processes tocomplete, number of rounds, etc are calculated for our
innovative algorithm.
Algorithms: -
Round Robin
• One of the oldest, simplest, fairest and most widely used algorithm is
round robin (RR).
• In the round robin scheduling, processes are dispatched in a FIFO
manner but are given a limited amount of CPU time called a time-
slice or a quantum.
• If a process does not complete before its CPU-time expires, the CPU
is preempted and given to the next process waiting in a queue. The
preempted process is then placed at the back of the ready list.
• Round Robin Scheduling is preemptive (at the end of time-slice)
therefore it is effective in time-sharing environments in which the
system needs to guarantee reasonable response times for interactive
users.
• The only interesting issue with round robin scheme is the length of
the quantum. Setting the quantum too short causes too many context
switches and lower the CPU efficiency. On the other hand, setting the
quantum too long may cause poor response time and approximates
FCFS.
• In any event, the average waiting time under round robin scheduling
is often quite long.
PROCESS -0 0 6
PROCESS-1 0 5
PROCESS-2 0 2
PROCESS-3 0 3
PROCESS-4 0 9
chart:
P0 P1 P2 P3 P4 P0 P1 P3 P4 P0 P1 P4
0 2 4 6 8 10 12 14 15 17 19 20 25
PROCESS-0 13 19
PROCESS-1 15 20
PROCESS-2 4 6
PROCESS-3 12 15
PROCESS-4 16 23
Average waiting time=12
PROCESS-0 10 16
PROCESS-1 5 10
PROCESS-2 0 2
PROCESS-3 2 5
PROCESS-4 16 25
Average waiting time=6.600
PROCESS -0 5 5
PROCESS-1 4 6
PROCESS-2 3 7
PROCESS-3 1 9
PROCESS-4 2 2
PROCESS-5 6 3
Time quantum=3ms
Gantt chart:
CPU P3 P4 P2 P1 P3 P0 P5 P2 P1 P3 P0 P2
PROCESS-0 22 27
PROCESS-1 17 23
PROCESS-2 23 30
PROCESS-3 20 29
PROCESS-4 2 4
PROCESS-5 12 15
Therefore, Average waiting time=16 Average
turnaround time=21.33
burst time=2
IDEAL
0 1 4 6 9 11 14 17 20 23 26 29 32 33
PROCESS-0 1 6
PROCESS-1 10 16
PROCESS-2 23 30
PROCESS-3 19 28
PROCESS-4 2 4
PROCESS-5 5 8
Therefore, Average waiting time=10
COMPARISION: -
CODE:
#include<stdio.h>
int main(){
int n,i,j,bt[100],at[100],po,temp,min,smt,sum=0,num,b[100],time=
0,max,k,p[100],l,wt [100],tt[100],g[100],st[100],f=0,m;
printf("Enter Number of Process:");
scanf("%d",&n);
num=n;
for(i=0;i<n;i++){
printf("Enter the brust time of Process-%d:",i);
scanf("%d",&bt[i]);
printf("Enter the arival time of Process-%d:",i);
scanf("%d",&at[i]);
p[i]=i;
wt[i]=0;
}
int a=at[0];
for(i=0;i<n;i++){
if(at[i]<a)
a=at[i];
}
if(a!=0){
for(i=0;i<n;i++){
at[i]=at[i]-a;
}
for(i=0;i<n;i++){
min=bt[i];
po=i;
for(j=i;j<n;j++){
if(bt[j]<min && at[i]==at[j]){
min=bt[j];
po=j;
}
}
temp=bt[po];
bt[po]=bt[i]; bt[i]=temp;
temp=at[po];
at[po]=at[i];
at[i]=temp;
temp=p[po]; p[po]=p[i];
p[i]=temp;
}
for(i=0;i<n;i++){
min=at[i]; po=i;
for(j=i;j<n;j++){
if(at[j]<min){
min=at[j];
po=j;
}
}
temp=bt[po];
bt[po]=bt[i];
bt[i]=temp;
temp=at[po];
at[po]=at[i];
at[i]=temp;
temp=p[po];
p[po]=p[i];
p[i]=temp;
}
min=bt[0];
for(m=0;m<n;m++){
if(min>bt[m]){
min=bt[m];
}
}
for(i=0;i<n;i++){
sum=sum+bt[i];
}
sum=sum/n; smt=(sum+min)/2;
for(i=0;i<n;i++){
b[i]=bt[i];
for(i=0;i<n;i++){
if(b[i]!=0){
if(smt<b[i] ){
wt[i]=(time-at[i])-(bt[i]-b[i]);
;
b[i]=b[i]-smt;
time=time+smt;
tt[i]=time-at[i];
if(b[i]<=smt){
time=time+b[i]; b[i]=0;
tt[i]=time-at[i];
num--;
}
}
else{
wt[i]=(time-at[i])-(bt[i]-b[i]);
time=time+b[i];
b[i]=0;
num--;
tt[i]=time-at[i];
}
}
for(j=i+1;j<n && j!=i;j++){
min=b[j];
po=j;
for(k=j;k<n;k++){
}
if(i==n-1){
i=-1;
if(num==0){
break;
}
}
}
printf("process-id waitingtimeturnaroundtime \n");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i==p[j]){
printf("process-%d%d%d\n",p[j],wt[j],tt[j]);
}
}
}
int s=0,s1=0;
for(i=0;i<n;i++){
s=s+wt[i];
s1=s1+tt[i];
}
OUTPUT: -
REFERENCES: -
• [3]Silberschatz, A., Galvin, P. B., and Gagne, G. 2005. Operating System Concepts. John
Wiley and Sons Inc.
• A. Abdulrahim, S. E. Abdullahi, and J. B. Sahalu, "A New Improved Round Robin (NIRR)
Scheduling Algorithm," International Journal of Computer Applications, Vol. 90, No. 4,
2014, 27- 33.