You are on page 1of 25

DAYANANDA SAGAR UNIVERSITY

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


SCHOOL OF ENGINEERING
DAYANANDA SAGAR UNIVERSITY
KUDLU GATE
BANGALORE - 560068

MINI PROJECT REPORT


ON
“PRIORITY SHEDULING”

Operating Systems Laboratory(20CS3506)


5th SEMESTER
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE & ENGINEERING

Submitted by

Sharanesh Prabhu Upase-(ENG21CS1018)


Sudarshan Shetty -(ENG20CS0363)
Steevan -(ENG20CS0361)
Shrayas S-(ENG20CS0346)

Under the supervision of


Prof.Bondu Venkateshvaralu
DAYANANDA SAGAR UNIVERSITY
School of Engineering, Kudlu Gate, Bangalore-560068

CERTIFICATE

This is to certify that Mr./Ms. bearing USN

has satisfactorily completed his/her Mini Project as prescribed by


the University for the semester B.Tech. programme in Computer
Science & Engineering during the year at the School of Engineering,
Dayananda Sagar University., Bangalore.

Date:
Signature of the faculty in-charge

Max Marks Marks Obtained

Signature of Chairman
Department of Computer Science & Engineering
DECLARATION

We hereby declare that the work presented in this mini project entitled –
“Priority Scheduling” has been carried out by us and it has not been
submitted for the award of any degree, diploma or the mini project of any
other college or university.

Sharanesh Prabhu Upase -(ENG20CS1018)


Sudarshan Shetty -( ENG20CS0363)
Steevan -( ENG20CS0361)
Shrayas S -( ENG20CS0346)
ACKNOWLEDGEMENT

The satisfaction that accompanies the successful completion of task would


be incomplete without the mention of the people who made it possible
and whose constant guidance and encouragement crown all the efforts
with success.

We are especially thankful to our Chairman Dr.Girisha G S, for


providing necessary departmental facilities, moral support and
encouragement.

We are very much thankful to our guide Prof.Bondu Venkateshvaralu,


for providing help and suggestions in completion of this min project
successfully.

We have received a great deal of guidance and co-operation from our


friends and we wish to thank all that have directly or indirectly helped us
in the successful completion of this project work.

Sharanesh Prabhu Upase -(ENG20CS1018)


Sudarshan Shetty -( ENG20CS0363)
Steevan -( ENG20CS0361)
NAME 4-( ENG20CS0346)
TABLE OF CONTENTS

Contents Page no
1.Introduction 08
2.Problem Statement 09
3.S/W & H/W Requirements 10
4.Design 11
4.1 Algorithm/Methodology 11
4.2 Description of Modules/Program 11
5.OutPut Screenshots 21
6.Conclusion 24
7.References 25
ABSTRACT

Scheduling is one of the most important activities of the process manager which
take decision to choose which of the process in the ready queue will be assigned
to the CPU. There are different types of scheduling algorithms available for
taking decision. One of them is Priority Scheduling Algorithm, which is based on
the priority assigned to each process. In priority scheduling the Processes are
executed on the basis of priority, the process having highest priority is executed
first. In case of similar priority FCFS is used. In this paper, the priority scheduling
algorithm is used in such a way that, in case of similar priority SJF algorithm is
used instead of FCFS and average waiting time and average turnaround time is
calculated. The comparative analysis is performed on the SJF based priority
scheduling and FCFS based priority scheduling to compare the average waiting
time and average turnaround time Index Terms-CPU, FCFS, SJF, priority.
CONTENTS

SL.NO Page No

Cover Page………………………………………………………….... i
Certificate…………………………………………………………….. ii
Declaration……………………………………………………………. iii
Acknowledgement…………………………………………………….. iv
Contents………………………………………………………………... v
Abstract…………………………………………………………………vi

Chapters:

1. Introduction…………………………………………………... 8
2. Problem Statement…………………………………………… 9
3. S/W & H/W Requirements…………………………………... 10
4. Design………………………………………………………... 11
4.1 Algorithm/Methodology
4.2 Description of Modules/Program
5. Output Screenshots…………………………………………… 21
6. Conclusion……………………………………………………. 24
7. References……………………………………………………. 25
Chapter:1

INTRODUCTION
Priority Scheduling is a method of scheduling processes that is
based on priority. In this algorithm, the scheduler selects the
tasks to work as per the priority.
The processes with higher priority should be carried out first,
whereas jobs with equal priorities are carried out on a round-
robin or FCFS basis. Priority depends upon memory
requirements, time requirements, etc.
Chapter:2
PROBLEM STATEMENT
One of the most important problems in operating systems
designing is CPU Scheduling and challenge in this field is to
build a program to achieve proper scheduling. In case of
priority scheduling algorithm when similar priority jobs arrive
then FCFS is used and as a consequence the average waiting
and turnaround time becomes relatively higher. The process
that arrives first is executed first, no matter how long it takes
the CPU. So in this case if long burst time processes are execute
earlier, then other process will remain in waiting queue for a
long time. This type of arrangement of processes in the ready
queue results in the higher average waiting and turnaround
time.
Chapter:3
REQUIREMENTS
Environment Used: Java

Hardware Used
System: intel i3 or later

Storage:10 GB or more

Ram:8GB or More

Software Requirements
• Net Beans IDE
• Virtual Box
Chapter:4
DESIGN
4.1 ALGORITHM/METHODOLOGY
for (int i = 0; i < numberOfProcess - 1; i++)

for (int j = 0; j < numberOfProcess - 1; j++)

if (priority[j] > priority[j + 1]) {

temp ← priority[j];

priority[j] ← priority[j + 1];

priority[j + 1] ← temp;

temp ← burstTime[j];

burstTime[j] ← burstTime[j + 1];

burstTime[j + 1] ← temp;

temp2 ← process[j];

process[j] ← process[j + 1];

process[j + 1] ←temp2;

4.2 DESCRIPTION OF MODULES/PROGRAM


WindowAdapter:
The class WindowAdapter is an abstract (adapter) class for receiving window events. All
methods of this class are empty. This class is convenience class for creating listener objects.

WindowEvent:
A low- level event that indicates that a window has changed its status. This low-level event is
generated by a window object when it is opened, closed, activated, deactivated, iconified, or
when focus is transferred into or out of the window.

Swing:
Swing is a lightweight java (GUI)that is used to create various applications. Swing has
platform-independent components. It enables the user to create buttons and scroll bars. Swing
includes packages for creating desktop applications in java.
File:
In java, with the help of file class, we can work with files. The files class is inside the java.io
package .the files class can used by creating an object of the class and then specifying the name
of the file.

Random:
Random class is part of java. util package. An instance of java Random class is used to generate
random numbers. This class provides several methods to generate random numbers of type
integer, double, long, float etc.

PROGRAM CODE:
import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.*;

import java.io.File;

import java.util.Random;

public class SchedulingGUI extends JFrame {

private String[] algorithms = {"Priority Scheduling"};

private String sourcePath = new String();

public static int NUM_OF_PROCESSES = 0;

static String selectedAlgo = new String();

public SchedulingGUI() {

initComponents();

jLabel7.setIcon(new javax.swing.ImageIcon("src\\main\\java\\dark-abstract-tech-
background_53876-90630.jpg"));

setResizable(false);

setTitle("CPU Scheduling Simulator");

jComboBox1.setModel(new DefaultComboBoxModel<>(algorithms));

addWindowListener(new WindowListener());
setLocationRelativeTo(null);

private class WindowListener extends WindowAdapter {

public void windowOpened(WindowEvent e) {

TitleThread thread = new TitleThread("Simulation", jLabel1, 200);

thread.start();

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-


BEGIN:initComponents

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jLabel2 = new javax.swing.JLabel();

jComboBox1 = new javax.swing.JComboBox<>();

jLabel3 = new javax.swing.JLabel();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jLabel4 = new javax.swing.JLabel();

jLabel1 = new javax.swing.JLabel();

jLabel5 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

nextStep2 = new javax.swing.JButton();

jLabel6 = new javax.swing.JLabel();


jLabel7 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(0, 102, 102));

jPanel1.setLayout(new AbsoluteLayout());

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

jLabel2.setForeground(new java.awt.Color(255, 255, 255));

jLabel2.setText("# of Process:");

jPanel1.add(jLabel2, new AbsoluteConstraints(320, 290, 130, 30));

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item


1", "Item 2", "Item 3", "Item 4" }));

jPanel1.add(jComboBox1, new AbsoluteConstraints(490, 190, 140, 30));

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

jLabel3.setForeground(new java.awt.Color(255, 255, 255));

jLabel3.setText("Algorithm:");

jPanel1.add(jLabel3, new AbsoluteConstraints(320, 190, 100, 30));

jButton1.setText("Browse");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

});
jPanel1.add(jButton1, new AbsoluteConstraints(490, 240, 140, 30));

jButton2.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N

jButton2.setText("Team Info");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

});

jPanel1.add(jButton2, new AbsoluteConstraints(0, 500, 100, 30));

jLabel4.setFont(new java.awt.Font("Bookman Old Style", 1, 48)); // NOI18N

jLabel4.setForeground(new java.awt.Color(255, 255, 255));

jLabel4.setText("CPU Scheduling");

jPanel1.add(jLabel4, new AbsoluteConstraints(280, 10, 420, 80));

jLabel1.setFont(new java.awt.Font("Bookman Old Style", 3, 18)); // NOI18N

jLabel1.setForeground(new java.awt.Color(255, 255, 255));

jLabel1.setText("Simulation");

jPanel1.add(jLabel1, new AbsoluteConstraints(410, 90, 120, -1));

jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

jLabel5.setForeground(new java.awt.Color(255, 255, 255));

jLabel5.setText("Source:");

jPanel1.add(jLabel5, new AbsoluteConstraints(320, 240, 70, 30));

jTextField1.setText("0");
jPanel1.add(jTextField1, new AbsoluteConstraints(490, 290, 140, 30));

nextStep2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

nextStep2.setText("Start");

nextStep2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

nextStep2ActionPerformed(evt);

});

jPanel1.add(nextStep2, new AbsoluteConstraints(410, 370, 130, 40));

jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

jLabel6.setForeground(new java.awt.Color(255, 255, 255));

jLabel6.setText("(0 <= N <= 10)");

jPanel1.add(jLabel6, new AbsoluteConstraints(650, 290, 120, 30));

jLabel7.setIcon(new javax.swing.ImageIcon("D:\\Programming
Files\\CPUSchedulingSimulation\\src\\main\\java\\dark-abstract-tech-background_53876-
90630.jpg")); // NOI18N

jPanel1.add(jLabel7, new AbsoluteConstraints(0, 0, 960, 530));

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 957,


javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 533,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(0, 0, Short.MAX_VALUE))

);

jPanel1.getAccessibleContext().setAccessibleName("");

pack();

setLocationRelativeTo(null);

}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_jButton1ActionPerformed

JFileChooser fileChooser = new JFileChooser();

fileChooser.showOpenDialog(null);

File file = fileChooser.getSelectedFile();

sourcePath = file.getAbsolutePath();

}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_jButton2ActionPerformed

JOptionPane.showMessageDialog(null, "Developers:\n\nSharanesh Upase CSE-


V.\nSudarshan Shetty CSE-V.\nShreyas S CSE-V.\nSteevan CSE-V.");

}//GEN-LAST:event_jButton2ActionPerformed
private void nextStep2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_nextStep2ActionPerformed

int numOfProcesses = Integer.parseInt(jTextField1.getText());

if(sourcePath.isEmpty())

JOptionPane.showMessageDialog(null, "ERROR: Please input the source of computation");

else if(numOfProcesses <= 0)

JOptionPane.showMessageDialog(null, "ERROR: Please input the appropriate number of


processes");

else {

selectedAlgo = jComboBox1.getSelectedItem().toString();

NUM_OF_PROCESSES = Integer.parseInt(jTextField1.getText());

Job[] jobs = new Job[NUM_OF_PROCESSES];

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

String processID = "P"+i;

long arrivalTime = (new java.util.Random().nextInt(9) + 1) * 300;

long burstTime = (new java.util.Random().nextInt(3) + 1) * 100;

long STRTTIME = System.nanoTime();

Job newJob = new Job(processID, arrivalTime, burstTime, STRTTIME);

jobs[(i-1)] = newJob;

CalcSimulation sim = newCalcSimulation(jobs, NUM_OF_PROCESSES, sourcePath,


selectedAlgo);

sim.start();

this.dispose();

}//GEN-LAST:event_nextStep2ActionPerformed

public static void main(String args[]) {


try {

for (javax.swing.UIManager.LookAndFeelInfo info :


javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new SchedulingGUI().setVisible(true);

});

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JButton jButton1;


private javax.swing.JButton jButton2;

private javax.swing.JComboBox<String> jComboBox1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;

private javax.swing.JLabel jLabel7;

private javax.swing.JPanel jPanel1;

private javax.swing.JTextField jTextField1;

private javax.swing.JButton nextStep2;

// End of variables declaration//GEN-END:variables

}
Chapter:5
OUTPUT SNAPSHOTS

Fig-1

Fig-2
Fig-3

Fig-4
Fig-5
Chapter:6
CONCLUSION
There are many scheduling algorithms having their own benefits and drawbacks. Scheduling
can also be done on the basis of priority. Each process assigned a priority and the process
which has highest priority will execute first. In case of similar priority generally FCFS is used
to select the next process. If SJF based priority scheduling algorithm is used when two or more
process having similar priority, instead of FCFS, then the average waiting time and average
turnaround time is reduced. We proposed SJF based priority scheduling algorithm in which,
the process that having lowest burst time will execute first. The existing FCFS based priority
scheduling algorithm and proposed SJF based priority scheduling algorithm is analyzed and
the result shows that the average waiting time and average turnaround time is reduced.

.
Chapter:7
REFERENCES
[1]F. Kanehiro, H. Hirukawa, and S. Kajita. OpenHRP: Open Architecture Humanoid
Robotics Platform. The International Journal of Robotics Research, 23(2):155–165, 2004.

[2] T. Taira, N. Kamata, and N. Yamasaki. Design and Implementation of Reconfigurable


Modular Robot Architecture. In Proceedings of the 2005 IEEE/RSJ International Conference
on Intelligent Robots and Systems, pages 3566–3571, 2005.

[3] H.S. Ahn, Y. M. Beak, I.-K. Sa, W. S. Kang, J. H. Na, and J. Y. Choi. Design of
Reconfigurable Heterogeneous Modular Architecture for Service Robots. In IEEE/RSJ 2008
International Conference on Intelligent Robots and Systems, pages 1313–1318, Sept. 2008.

[4] F. R. T. Center. http://www.furo.org/

[5] K. Lin, S. Natarajan, and J. W. S. Liu. Imprecise Results: Utilizing Partial Computations in
Real-Time Systems.

[6] Proceedings of the 8th IEEE Real-Time Systems Symposium, pages 210–217, Dec. 1987.

[7] Abraham Silberschatz, Peter Baer Galvin, Greg Gagne, “Operating System Concepts”, 7th
Edition, John Wiley & Sons, ISBN: 978-81-265-2051-0, 2005

You might also like