0% found this document useful (0 votes)
108 views

CPU Scheduling Program in C++ - Code With C

lecture note

Uploaded by

Habtie
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views

CPU Scheduling Program in C++ - Code With C

lecture note

Uploaded by

Habtie
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CPU Scheduling Program in C++

June 23, 2017

CPU Scheduling Program in C++

In the beginning of the program, I define a class name ‘cpuschedule’, the class contains seven public methods.

Getdata method contains the user input for no. of process and burst time for process. Fcfs method calculates First come First
served Algorithm and show the Total and Average Weighting Time. Sjf method calculates Shortest job First Algorithm, SjfNp is
Shortest job First Algorithm with Non Preemptive, SjfP is Shortest job First Algorithm with Preemption and RoundRobin method is
Round Robin Algorithm  and show the Total and Average Weighting Time.

The main function, in the main function there is a infinity loop with a termination point. When the user enters an choice the with
the following number the program goes to the corresponding method call the Algorithm or User Input for calculation.

Method definition:
Fcfs():

Step 1: it loops through all the burst time process.

Step 2: now it store weight in the array.

Step 3: after that, the third loop in the method calculates the total weight time and we can divide the total time with the no. of
process to find the average time.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the
use of ALL the cookies.

Do not sell my personal information.

Cookie settings ACCEPT


Sjf():

Step 1: firstly the program loops through the time for process then

Step 2: it sort the burst time process and

Step 3: calculate the weight by adding the previous value of weight and the burst time which stored inside the array.

Step 4: finally the total weighting time is calculate by adding the current time and weight

SjfNp():

Step 1: in the beginning of the method it prints out the burst time for the process and gets the input from the arrival time of the
process.

Step 2: after that the burst array and arrival time array sort their position by ascending order.

Step 3: now program prints the burst time and arrival time.

Step 4: the total weighting time is calculate by adding the current time with the result of weight subtracting by the arrival time.

Step 5: finally the average weight calculation, total weight divide by the number of processes.

Priority()

Step 1: shows Burst time and get input from the priority for process from the user

Step 2: it calculate the weight by w=w+B[i] if current value of P equals to j

Step 3: then the method loop through the current time and adding the time with all weights in the array to find the total time and
divide by the processes will show the average time.

SjfP():

Step 1: in the beginning of the method it prints out the burst time for the process and gets the input from the arrival time of the
process and we calculate assign the biggest value of arrival time in the time variable.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the
Step 2: now while the t is less than Time and if arrival time is less or equal t and burst time not equals zero then the program
use of ALL the cookies.

Do not sell my personal information.


prints the weight. Next for burst time is zero the program loop through with the condition of j is less then n and the flag is not
equal zero and if (S[j]!=’F’ && B[i]>B[j] && A[j]<=t && i!=j)  this satisfies then the program set the flag to 0 and add weight in
Cookie settings ACCEPT
the weight array.

Step 3: then the program prints the remaining burst time

Step 4: after that the weight info shows in the console by loop

Step 5: now after subtracting the arrival time with the weight the program calculate the total time and average time.

RoundRobin():

Step 1: in the beginning of the method it prints out the burst time.

Step 2: get the time Quantum.

Step 3: m = max / tq + 1 TO find the dimension of the Rrobin array

Step 4: Now, initializing Robin array by a two dimensional array.

Step 5: placing value in the Rrobin array

Step 6: Display the robin array.

Step 7: calculate the weighting time, total time and average time.

Download Source Code for CPU Scheduling Program in C++


[sociallocker]

CPU scheduling program in C++

Password:codewithc.com

[/sociallocker]

CODEWITHC
© CODEWITHC.COM. All rights reserved.

Code with C is a comprehensive compilation of Free projects, source codes, books, and tutorials in Java, PHP,.NET, Python, C++, in C programming language, and more. Our
We use cookies onmain mission
our websiteis to help out programmers
to give and relevant
you the most coders, students and learners
experience in general, with relevant
by remembering resources and materials
your preferences and repeatin thevisits.
field of computer programming.
By clicking “Accept”, you consent to the
use of ALL the cookies.

Do not sell my personal information.    

Cookie settings ACCEPT


Projects
C PROJECTS

C++ PROJECTS

PYTHON PROJECTS

ASP.NET PROJECTS

PHP PROJECTS

VB & VB.NET PROJECTS

About Us
HOME

ABOUT US

CONTACT US

TERMS OF USE

PRIVACY POLICY

Popular Category
C TUTORIALS 155

BLOG 86

C++ TUTORIAL 72

JAVA TUTORIALS 53

C PROJECTS 51

ASP.NET PROJECTS 48

JAVA PROJECTS 44

PYTHON TUTORIALS 39

Editor Picks
C Programming Language – A Step By Step Beginners Guide – 2023
December 14, 2022

What Every Programmer Should Know About Object-Oriented Programming


September 23, 2022

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the
use of ALL the cookies.

Do not sell my personal information.

Cookie settings ACCEPT

You might also like