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

CPU Scheduling Algorithmsreport

Uploaded by

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

CPU Scheduling Algorithmsreport

Uploaded by

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

A

MICRO-PROJECT REPORT ON

CPU Scheduling Algorithms

SUBMITTED BY: Rishikesh

GUIDED BY: Prof. Harsita Kaushik

MASTER OF COMPUTER APPLICATION

GOVERNMENT POLYTECHNIC, AHMEDNAGAR

(2023-24)
VIVEKANANDA GLOBAL UNIVERSITY,JAIPUR

CERTIFICATE
Rishikesh
of 1st Semester Master Of Computer Application students have
submitted their Micro-Project Report on
CPU Scheduling Algorithms

During academic session 2023- 2024 in the practical fulfilment course


for Operating System

Guide Head
Dr. Sanjay Sinha

Prof. Harshita Kaushik Department of Computer Application


ACKNOWLEDGEMENT

We would like to place on record my deep sense of gratitude to Prof. Harshita


Kaushik Dept. of Computer Application(MCA) for her generous guidance, help
and useful suggestions.

I express my sincere gratitude to HOD dr. Sanjay Sinha Head of Dept. of


Computer Application, for his stimulating guidance, continuous
encouragement and supervision throughout the course of present work.

I am extremely thankful to Prof. Harshita kaushik, Hod Dr.sanjay Sinha,


Vivekananda Global Univesity, Jaipur for providing me infrastructural facilities
to work in, without which this work would not have been possible.

Name of students
Rishikesh
CONTENTS

1. Rationale 5

2. Course Outcomes Integrated 5

3. Literature Review 6

4. Actual Procedure Followed 6

5. Actual Resources Used 7

6. Source Code 7-28

7. Output of the Micro-Project 28-31

8. Skill Developed / learning out of this Micro-Project 32

9. Benefits of this Micro-Project 32

10. Conclusion of this Micro-Project 32


CPU Scheduling Algorithms

1.0 Rationale

Scheduling algorithms are mainly scheduling policies which allocate processes in such
a way that optimizes CPU efficiency. Scheduling algorithms decide which of the processes in
the ready queue is allocated to the CPU. This software explains the behavior of scheduling
algorithms against a of process loads. The user can specify the number of processes, and I/O
blocking time for each process. At the end of the result is shown. There are mainly four
scheduling algorithms First Come First Serve (FCFS), Shortest Job First Scheduling (SJF), Round
Robin Scheduling (RR), and Priority Scheduling. FCFS is a non-preemptive scheduling that
follows first in first out basic. The oldest process in the ready queue will be selected for
execution. The average waiting time for FCFS is often quite long. It suffers through Convey
effect in which a long CPU bound job may hang the CPU and may force shorter jobs to wait
longer. In SJF the process with the shortest expected processing time is selected for execution
among the processes in ready queue. It gives the minimum average time and can be
preemptive or non-preemptive. In Round robin algorithm the CPU suspends the current job
when the reserved time slice or quantum is finished. The job is then placed at the end of the
ready queue if it is not completed. If the quantum is too short, the CPU will suspend more
time on context switching and if quantum is too long, the interactive process will suffer .So,
the quantum should be chosen wisely. Priority Scheduling Algorithm, in this priority is
associated with each process. The CPU is allocated to the process with highest priority. SJF is
a special case of priority scheduling algorithm. The response time for the highest priority
process is really good but at the same time the lowest priority process may suffer Starvation.

2.0 Course Outcomes Integrated

• Install operating system and configure it.


• Use operating system tools to perform various functions.
• Execute process commands for performing process management operations.
• Calculate efficiency of different memory management techniques.
• Apply scheduling algorithms to calculate turnaround time and average waiting
time.
3.0 Literature Review

In this section, articles on CPU scheduling algorithms, are reviewed and classified according to
algorithms. In the researchers suggested comparing the three CPU algorithms based on each
algorithm's waiting time to find the most appropriate algorithm for a particular process. They tested
each algorithm individually and tested their results. In the researchers proposed an improved version
of the round-robin CPU scheduling algorithm based on the k means clustering technique to combine
the advantages of favor short process and low scheduling overhead of round robin to reduce average
waiting time, turnaround time. The k means algorithm is used to group similar processes in clusters.
The proposed algorithm was compared with PWRR, TRR, PRR, SRR, and ADRR algorithms. The results
showed that the proposed algorithm has a better performance by minimizing time cost compared
with other algorithms. In these researchers created a fast system with fewer resources through the
CPU scheduling algorithm. They reduced the algorithm's runtime and efficiency constraints. They
implemented and developed algorithms FCFS, SJF, PS, RR, and DRR. Finally, they compared these
algorithms, and DRR was the best among them. In the researchers proposed scheduling algorithms to
improve the operating system's real-time performance, and the CPU has been proposed. The
proposed CPU is based on combining round scheduling (RR) and priority-based (PB) scheduling
algorithms. Experimental results showed that the new algorithm improves all the round-robin
scheduling algorithm CPU flaws.

4.0 Actual Procedure Followed

The problem related to the project is identified and the significance of the study is
determined. The objective and also scope of study are outlined and the feasibility of the
project work is ensured to be developed within the time frame given. The solution to the
problem statement is studied and the types of system to be develop and tools used for
developing the system are also identified through literature reviews.
Series of studies has been performed to gain further knowledge CPU scheduling
algorithms . Also, readings was done to get better understanding on how algorithms works.
The next phase to develop the architecture on how the system will works. This will
give the clear picture and understanding on how the system will operate and to avoid
developing a system that does not solving the problem it intended to solve.
5.0 Actual Resources Used

S. No. Name of Specifications Qty Remarks


Resource/material
1 Computer System Windows 10 1
2 Internet Chrome 1
3 MS Word 2019 1
4 Eclipse 2022 1
5 Launch4j 3.87

6.0 Source Code

FCFS.java
package CPU_Algorithms;

import java.util.*;

public class First_Come_First_Serve {


int length;
int start;
float AverageWaitingTime;
float AverageTurnAroundTime;
float AverageResponseTime;
int totalBurstTime = 0;
Vector gantt_Chart[];
Object data[][];

First_Come_First_Serve(Object information[][]) {
gantt_Chart = new Vector[4];
for (int i = 0; i < 4; i++) {
gantt_Chart[i] = new Vector();
}

data = information;
length = data.length;
Object copy_burst_times[] = new Object[length];
sortbyColumn(data, 2);
for (int i = 0; i < length; i++) {
copy_burst_times[i] = data[i][3];
}
getComletionTime();

for (int i = 0; i < length; i++) {


data[i][3] = copy_burst_times[i];
if ((int) data[i][8] <= -1) {
data[i][8] = 0;
}
}
getTurnAroundTime();
getTotalWaitingTime();
getTotaResponseTime();

AverageWaitingTime = getAverageTime(7);
AverageTurnAroundTime = getAverageTime(6);
AverageResponseTime = getAverageTime(8);

sortbyColumn(data, 0);
}

public void getTotalBurstTime() {


for (int i = 0; i < length; i++) {
totalBurstTime = totalBurstTime + (int) data[i][3];
}
}

public void getComletionTime() {


getTotalBurstTime();
int flag = 0;
while (totalBurstTime > 0) {
for (int i = 0; i < length; i++) {
if (start >= (int) data[i][2]) {
if ((int) data[i][3] == 0) {

} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
start = start + (int) data[i][3];
gantt_Chart[2].add(start);
totalBurstTime = totalBurstTime - (int)
data[i][3];
data[i][3]=0;
data[i][5] = start;
}
} else {
flag = 1;
}
}
if (flag == 0) {

} else {
if (totalBurstTime == 0) {

} else {
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[0].lastElement().toString().equals("Idle")) {
start = start + 1;

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
gantt_Chart[2].add(start);
} else {
gantt_Chart[0].add("Idle");
gantt_Chart[1].add(start);
start = start + 1;
gantt_Chart[2].add(start);
}
}
}
}

public void getTurnAroundTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][6] = (int) data[i][5] - (int) data[i][2];
}
}
}

public void getTotalWaitingTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][7] = (int) data[i][6] - (int) data[i][3];
}
}
}

public void getTotaResponseTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][8] = (int) data[i][7];
}
}
}

public float getAverageTime(int j) {


float averageTime = 0;
for (int i = 0; i < length; i++) {
averageTime = averageTime + (int) data[i][j];
}
averageTime = averageTime / length;
return averageTime;
}

public void sortbyColumn(Object arr[][], int col) {

Arrays.sort(arr, new Comparator<Object[]>() {

@Override
public int compare(final Object[] entry1, final Object[] entry2) {

if ((int) (entry1[col]) >= (int) (entry2[col]))


return 1;
else
return -1;
}
});
}
}

SJF.java

package CPU_Algorithms;
import java.util.*;
public class Shortest_Job_First_Preemtive {
int length;
int start;
float AverageWaitingTime;
float AverageTurnAroundTime;
float AverageResponseTime;
int totalBurstTime = 0;
Vector gantt_Chart[];
Object data[][];

Shortest_Job_First_Preemtive(Object information[][]) {
gantt_Chart = new Vector[4];
for (int i = 0; i < 4; i++) {
gantt_Chart[i] = new Vector();

}
data = information;
length = data.length;
Object copy_burst_times[] = new Object[length];
for (int i = 0; i < length; i++) {
copy_burst_times[i] = data[i][3];
}
sortbyColumn(data, 2);
getComletionTime();
sortbyColumn(data, 0);
for (int i = 0; i < length; i++) {
data[i][3] = copy_burst_times[i];
if ((int) data[i][8] <= -1) {
data[i][8] = 0;
}
}
getTurnAroundTime();
getTotalWaitingTime();
AverageWaitingTime = getAverageTime(7);
AverageTurnAroundTime = getAverageTime(6);
AverageResponseTime = getAverageTime(8);
}

public void getTotalBurstTime() {


for (int i = 0; i < length; i++) {
totalBurstTime = totalBurstTime + (int) data[i][3];
}
}

public void getComletionTime() {


getTotalBurstTime();
sortByBurstTime();
while (totalBurstTime > 0) {
int count = 0;
for (int i = 0; i < length; i++) {
if ((int) data[i][2] <= start) {

} else {
count = 1;
break;
}
}
if ((int) data[0][3] == 0) {
for (int i = 0; i < length; i++) {
Object temp[] = data[0];
data[0] = data[i];
data[0] = temp;
}
}

for (int i = 1; i < length; i++) {


if (start >= (int) data[i][2] && ((int) data[0][3] > (int) data[i][3])
|| (int) data[0][3] == 0) {

Object temp[] = data[0];


data[0] = data[i];
data[i] = temp;
}
}
if ((int) data[0][3] != 0) {
if (count == 1) {
if (start >= (int) data[0][2]) {
int i = 0;
int flag = 0;
for (int k = 0; k < length; k++) {
if ((int) data[k][3] == 0) {
} else {
flag++;
}
}
if (flag == 1) {
if ((int) data[i][8] == -1) {
data[i][8] = start - (int) data[i][2];
}
if (gantt_Chart[0].size() >= 1
&&
gantt_Chart[3].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
totalBurstTime = totalBurstTime - (int)
data[i][3];
start = start + (int) data[i][3];
data[i][3] = 0;
gantt_Chart[2].add(start);
data[i][5] = start;
} else {
if ((int) data[i][8] == -1) {
data[i][8] = start - (int) data[i][2];
}
if (gantt_Chart[0].size() >= 1
&&
gantt_Chart[3].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
start = start + 1;
data[i][3] = (int) data[i][3] - 1;
gantt_Chart[2].add(start);
totalBurstTime = totalBurstTime - 1;
data[i][5] = start;
gantt_Chart[3].add(data[i][0]);
}
} else {
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[0].lastElement().toString().equals("Idle")) {
start = start + 1;

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
gantt_Chart[2].add(start);
} else {
gantt_Chart[0].add("Idle");
gantt_Chart[1].add(start);
start = start + 1;
gantt_Chart[2].add(start);
gantt_Chart[3].add("Idle");
}
}
} else {
if (start >= (int) data[0][2]) {
int i = 0;
int flag = 0;
for (int k = 0; k < length; k++) {
if ((int) data[k][3] == 0) {
} else {
flag++;
}
}
if (flag == 1) {
if ((int) data[i][8] == -1) {
data[i][8] = start - (int) data[i][2];
}
if (gantt_Chart[0].size() >= 1
&&
gantt_Chart[3].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
totalBurstTime = totalBurstTime - (int)
data[i][3];
start = start + (int) data[i][3];
data[i][3] = 0;
gantt_Chart[2].add(start);
data[i][5] = start;
} else {
if ((int) data[i][8] == -1) {
data[i][8] = start - (int) data[i][2];
}
if (gantt_Chart[0].size() >= 1
&&
gantt_Chart[3].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
start = start +(int) data[i][3];
gantt_Chart[2].add(start);
totalBurstTime = totalBurstTime - (int)
data[i][3];
data[i][5] = start;
data[i][3] = 0;
gantt_Chart[3].add(data[i][0]);
}
} else {
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[0].lastElement().toString().equals("Idle")) {
start = start + 1;

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
gantt_Chart[2].add(start);
} else {
gantt_Chart[0].add("Idle");
gantt_Chart[1].add(start);
start = start + 1;
gantt_Chart[2].add(start);
gantt_Chart[3].add("Idle");
}
}

}
}
}
}

public void getTurnAroundTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][6] = (int) data[i][5] - (int) data[i][2];
}
}
}

public void getTotalWaitingTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][7] = (int) data[i][6] - (int) data[i][3];
}
}
}

public float getAverageTime(int j) {


float averageTime = 0;
for (int i = 0; i < length; i++) {
averageTime = averageTime + (int) data[i][j];
}
averageTime = averageTime / length;
return averageTime;
}

public void sortbyColumn(Object arr[][], int col) {

Arrays.sort(arr, new Comparator<Object[]>() {

@Override
public int compare(final Object[] entry1, final Object[] entry2) {

if ((int) (entry1[col]) >= (int) (entry2[col]))


return 1;
else
return -1;
}
});
}

public void sortByBurstTime() {


for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if (data[i][2] == data[j][2]) {
if ((int) data[i][3] < (int) data[j][3]) {
Object temp[] = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
}
}
}
Priority.java

package CPU_Algorithms;

import java.util.*;

public class Priority_Scheduling_Non_Preemtive {


int length;
int start;
float AverageWaitingTime;
float AverageTurnAroundTime;
float AverageResponseTime;
int totalBurstTime = 0;
Vector gantt_Chart[];
Object data[][];

Priority_Scheduling_Non_Preemtive(Object information[][]) {
gantt_Chart = new Vector[4];
for (int i = 0; i < 4; i++) {
gantt_Chart[i] = new Vector();
}

data = information;
length = data.length;
Object copy_burst_times[] = new Object[length];
sortbyColumn(data, 2);
sortByPriority();
for (int i = 0; i < length; i++) {
copy_burst_times[i] = data[i][3];
}

getComletionTime();
for (int i = 0; i < length; i++) {
data[i][3] = copy_burst_times[i];
if ((int) data[i][8] <= -1) {
data[i][8] = 0;
}
}
getTurnAroundTime();
getTotalWaitingTime();
getTotaResponseTime();

AverageWaitingTime = getAverageTime(7);
AverageTurnAroundTime = getAverageTime(6);
AverageResponseTime = getAverageTime(8);

sortbyColumn(data, 0);
}

public void getTotalBurstTime() {


for (int i = 0; i < length; i++) {
totalBurstTime = totalBurstTime + (int) data[i][3];
}
}

public void getComletionTime() {


getTotalBurstTime();
int flag = 0;
while (totalBurstTime > 0) {
for (int i = 0; i < length; i++) {
if (start >= (int) data[i][2]) {
if ((int) data[i][3] == 0) {

} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
start = start + (int) data[i][3];
gantt_Chart[2].add(start);
totalBurstTime = totalBurstTime - (int)
data[i][3];
data[i][5] = start;
data[i][3]=0;
}
} else {
flag = 1;
}
}
if (flag == 0) {

} else {
if (totalBurstTime == 0) {

} else {
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[0].lastElement().toString().equals("Idle")) {
start = start + 1;

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
gantt_Chart[2].add(start);
} else {
gantt_Chart[0].add("Idle");
gantt_Chart[1].add(start);
start = start + 1;
gantt_Chart[2].add(start);
}
}
}
}

public void getTurnAroundTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][6] = (int) data[i][5] - (int) data[i][2];
}
}
}

public void getTotalWaitingTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][7] = (int) data[i][6] - (int) data[i][3];
}
}
}

public void getTotaResponseTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][8] = (int) data[i][7];
}
}
}

public float getAverageTime(int j) {


float averageTime = 0;
for (int i = 0; i < length; i++) {
averageTime = averageTime + (int) data[i][j];
}
averageTime = averageTime / length;
return averageTime;
}

public void sortbyColumn(Object arr[][], int col) {

Arrays.sort(arr, new Comparator<Object[]>() {

@Override
public int compare(final Object[] entry1, final Object[] entry2) {

if ((int) (entry1[col]) >= (int) (entry2[col]))


return 1;
else
return -1;
}
});
}

public void sortByPriority() {


for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if (data[i][2] == data[j][2]) {
if ((int) data[i][4] < (int) data[j][4]) {
Object temp[] = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
}
int counter = (int) data[0][3];
for (int i = 1; i < length; i++) {
int burst = 0;
if (counter >= (int) data[i][2]) {
int flag = 0;
for (int m = i; m < length; m++) {
if ((int) data[i][4] > (int) data[m][4]) {
Object temp[] = data[i];
data[i] = data[m];
data[m] = temp;
burst = (int) data[m][3];
flag = 1;
} else {

}
}
if (flag == 1) {
counter = counter + burst;
} else {
counter = counter + (int) data[i][3];
}
} else {
counter++;
}
}

}
}
Round_Robin.java

package CPU_Algorithms;
import java.util.*;
public class Round_Robin {
int length;
int start;
int Time_Slice;
float AverageWaitingTime;
float AverageTurnAroundTime;
float AverageResponseTime;
int totalBurstTime = 0;
Vector gantt_Chart[];
Object data[][];
public Stack<Integer> stack = new Stack<Integer>();

Round_Robin(Object information[][], int Time_Slice) {


this.Time_Slice = Time_Slice;
gantt_Chart = new Vector[4];
for (int i = 0; i < 4; i++) {
gantt_Chart[i] = new Vector();

}
data = information;
length = data.length;
Object copy_burst_times[] = new Object[length];
sortbyColumn(data, 2);
for (int i = 0; i < length; i++) {
copy_burst_times[i] = data[i][3];
}
getComletionTime();
for (int i = 0; i < length; i++) {
data[i][3] = copy_burst_times[i];
if ((int) data[i][8] <= -1) {
data[i][8] = 0;
}
}
getTurnAroundTime();
getTotalWaitingTime();
AverageWaitingTime = getAverageTime(7);
AverageTurnAroundTime = getAverageTime(6);
AverageResponseTime = getAverageTime(8);

sortbyColumn(data, 0);
}

public void getTotalBurstTime() {


for (int i = 0; i < length; i++) {
totalBurstTime = totalBurstTime + (int) data[i][3];
}
}

public void getComletionTime() {


getTotalBurstTime();

checkQueue();
while (totalBurstTime > 0) {
if (stack.size() > 0) {
int i = stack.elementAt(0);
int flag = 0;
if ((int) data[i][3] >= Time_Slice) {
for (int k = 0; k < length; k++) {
if ((int) data[k][3] == 0) {
} else {
flag++;
}
}
if (stack.size() == 1 && flag == 1) {
if ((int) data[i][8] == -1) {
data[i][8] = start - (int) data[i][2];
}
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[0].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
totalBurstTime = totalBurstTime - (int)
data[i][3];
start = start + (int) data[i][3];
data[i][3] = 0;
gantt_Chart[2].add(start);
data[i][5] = start;
checkQueue();

} else {
if ((int) data[i][8] == -1) {
data[i][8] = start-(int)data[i][2];
}
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[3].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
start = start + Time_Slice;
data[i][3] = (int) data[i][3] - Time_Slice;
gantt_Chart[2].add(start);
totalBurstTime = totalBurstTime -
Time_Slice;
data[i][5] = start;
if ((int) data[i][3] == 0) {
checkQueue();

} else {
checkQueue();
int element = stack.elementAt(0);
stack.remove(0);
stack.push(element);
}
}

} else {
if ((int) data[i][8] == -1) {
data[i][8] = start;
}
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[3].lastElement().toString().equals(data[i][0].toString())) {

gantt_Chart[2].remove(gantt_Chart[2].lastElement());
} else {
gantt_Chart[0].add(data[i][1]);
gantt_Chart[1].add(start);
gantt_Chart[3].add(data[i][0]);
}
start = start + (int) data[i][3];
totalBurstTime = totalBurstTime - (int) data[i][3];
data[i][3] = 0;
gantt_Chart[2].add(start);
data[i][5] = start;
checkQueue();

}
} else {
if (gantt_Chart[0].size() >= 1 &&
gantt_Chart[0].lastElement().toString().equals("Idle")) {
start = start + 1;
gantt_Chart[2].remove(gantt_Chart[2].lastElement());
gantt_Chart[2].add(start);
checkQueue();
} else {
gantt_Chart[0].add("Idle");
gantt_Chart[1].add(start);
start = start + 1;
gantt_Chart[2].add(start);
gantt_Chart[3].add("Idle");
checkQueue();
}
}
}
}

public void getTurnAroundTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][6] = (int) data[i][5] - (int) data[i][2];
}
}
}

public void getTotalWaitingTime() {


for (int i = 0; i < length; i++) {
if ((int) data[i][3] == 0) {
} else {
data[i][7] = (int) data[i][6] - (int) data[i][3];
}
}
}

public float getAverageTime(int j) {


float averageTime = 0;
for (int i = 0; i < length; i++) {
averageTime = averageTime + (int) data[i][j];
}
averageTime = averageTime / length;
return averageTime;
}

public void sortbyColumn(Object arr[][], int col) {

Arrays.sort(arr, new Comparator<Object[]>() {

@Override
public int compare(final Object[] entry1, final Object[] entry2) {

if ((int) (entry1[col]) >= (int) (entry2[col]))


return 1;
else
return -1;
}
});
}
public void checkQueue() {
for (int i = 0; i < data.length; i++) {
if (start >= (int) data[i][2]) {
if (stack.search(i) == -1) {
stack.push(i);
}
}
if ((int) data[i][3] == 0) {
Object o = i;
stack.remove(o);
}
}
}
}

7.0 Outputs of the Micro-Projects

Home Page
Input Page

First Come First Serve


Shortest Job First Non-Preemptive

Shortest Job First Preemptive


Priority Scheduling

Round Robin
8.0 Skill Developed / learning out of this Micro-Project

• Using internet to solve problem


• Handling Information.
• Collecting Information.
• Communication Skills.

9.0 Benefits of this Micro-Project

• It works for algorithms such as FCFS, Round Robin with time quantum, Shortest
Job First and Priority Scheduling.
• It defines the process to schedule.
• It shows the Gantt-Chart of process execution.
• It computes average waiting time, mean response time, mean turnaround time,
Idle CPU time, and Busy CPU time.
• Easy to solve arithmetic problems related to CPU scheduling.

10.0 Conclusion of this Micro-Project

The software provides users with useful information how processes are executed in CPU. With
this, with this software it solves the real world arithmetic problems easily and accurate. This software
easy to use and convenient. With this project we learnt how processes interact with the cp und also
understood how algorithms chooses the processes from ram. Now we able to design the programs for
CPU scheduling algorithms

11.0 References

• { HYPERLINK "https://www.javatpoint.com/os-scheduling-algorithms" }
• { HYPERLINK "https://www.geeksforgeeks.org/cpu-scheduling-in-operating-
systems/" }
• { HYPERLINK "https://stackoverflow.com/" }

**************

You might also like