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

MP1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

MP1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

VIVEKANAND EDUCATION SOCIETY POLYTECHNIC

MICRO PROJECT
Academic year
2023-24

TITLE OF PROJECT

Implementation of Shortest Job First, FCFS and


Shortest Remaining Time CPU Scheduling Algorithm

Program:COMPUTER ENGINEERING Program code:CO5I-(A)

Course:OSY (Operating System) Course code: 22516


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Certificate

This is to certify that Mr/Ms Hemant.Bhatia, Gaurav.Punjai, Pooja.Makhija RollNo 37,38,

39of 5th Semester of Diploma in Computer Engineering Of Institute, VES POLYTECHNIC

(Code: 0004)has completed the Micro Project satisfactorily in Subject–OPERATING SYSTEM

(22516) for the academic year 2023- 2024. as prescribed in the curriculum.

Place: Chembur Enrollment No: 200040356-358

Date: ……………………… Exam Seat No: ………………………….

Subject Teacher Head of the Department Principal

1 | Page
INDEX

Academic year: 2023-24 Name of the faculty: Mr. Dileep Nitture

Program code: CO5I (A) Course & course code: 22516

Name of the candidates: Mr/Ms. Hemant.Bhatia, Gaurav.Punjabi, Pooja.Makhija

Roll No. 37, 38, 39 Enrollment No. 200040356-358

Sr.No Content Page No.

1 Project Proposal

2 Action plan

3 Resource required

4 Introduction

5 Actual Procedure

6 Output

7 Skill developed

8 Evaluation sheet

2 | Page
Annexure – I

Micro-Project Proposal

Implementation of Shortest Job First, FCFS and Shortest Remaining


Time CPU Scheduling Algorithm

1.0 Aim of the Micro-Project


This Micro-Project aims at
1. Implementing the FCFS Scheduling Algorithm
2. Implementing the Shortest Job First Scheduling Algorithm
3. Implementing the Shortest Remaining Time Scheduling Algorithm
4. Implementation leading to better understanding.

2.0 Course Outcomes Addressed


1. Install operating system and configure it. [✔]

2 Apply scheduling algorithms to calculate turnaround time and average waiting time. [✔]

3.0Proposed Methodology
Discussion about topic with guide and among group members
• Literature Survey
• Submission of project proposal
• Information collection and Analysis of Data
• Designing algorithm
• Designing flowchart
• Coding
• Testing
• Checking Final Output

3 | Page
4.0Action Plan

SR. Details of activity Planned Start Planned Name of Responsible


No. date Finish date Team Members

1 Finalization of project Title and


Scope

2 Project Definition and design


structure

3 Design procedure (algorithm)

4 Draw flowchart

5 Coding

6 Output

7 Report writing

8 Demonstration of project and final


submission

5.0Resources Required

Sr.No. Equipment Name with Broad Specification Remark if any

1 Laptop Inspiron 3509, i5, 11th Gen, 8GB RAM, 1TB HDD

2 Windows 11

3 Visual Studio Code

Name of Team Members with Roll Nos.

1.Hemant.Bhatia (37)
2Gaurav.Punjabi (38) Annexure – II
3.Pooja.Makhija (39)
4 | Page
Micro-Project Report

Implementation of Shortest Job First, FCFS and Shortest Remaining


Time CPU Scheduling Algorithm

1.0 Rationale
An Operating System is a basically a system program that controls the execution of application
programs and acts as an interface between applications and the computer hardware. It manages
the computer system resources to be used in an efficient manner. The main features of OS are
multitasking and multithreading. Using these features, we can execute more than one process at a
time. This requires CPU switching from one process to another process to keep it busy for
maximum time. Proper scheduling of CPU must be provided to get its maximum utilization.
There are many different scheduling algorithms out of which we will be implementing the SJF
and SRTF scheduling algorithm to know how the scheduling actually works.

2.0Aim of the Micro-Project


This Micro-Project aims at
1. Implementing the FCFS Scheduling Algorithm
2. Implementing the Shortest Job First Scheduling Algorithm
3. Implementing the Shortest Remaining Time Scheduling Algorithm
4. Implementation leading to better understanding.

3.0 Course Outcomes Addressed

1. Install operating system and configure it. [✔]


4. Apply scheduling algorithms to calculate turnaround time and average waiting time. [✔]

5 | Page
4.0 Literature Review
CPU Scheduling is a process of determining which process will own CPU for execution while
another process is on hold. Scheduling are of two types: Pre-emptive and non-pre-emptive.

Some of the CPU Scheduling criteria are as follows:


1.CPU utilization: The main objective of any CPU scheduling algorithm is to keep the CPU as
busy as possible. Theoretically, CPU utilization can range from 0 to 100 but in a real-time
system, it varies from 40 to 90 percent depending on the load upon the system.
2.Throughput: A measure of the work done by the CPU is the number of processes being
executed and completed per unit of time. This is called throughput. The throughput may vary
depending upon the length or duration of the processes.
3.Turnaround time: For a particular process, an important criterion is how long it takes to
execute that process. The time elapsed from the time of submission of a process to the time of
completion is known as the turnaround time. Turn-around time is the sum of times spent waiting
to get into memory, waiting in the ready queue, executing in CPU, and waiting for I/O. The
formula to calculate Turn Around Time = Compilation Time – Arrival Time.
4.Waiting time: A scheduling algorithm does not affect the time required to complete the
process once it starts execution. It only affects the waiting time of a process i.e. time spent by a
process waiting in the ready queue. The formula for calculating Waiting Time = Turnaround
Time – Burst Time.
5.Response time: In an interactive system, turn-around time is not the best criteria. A process
may produce some output fairly early and continue computing new results while previous results
are being output to the user. Thus another criteria is the time taken from submission of the
process of request until the first response is produced. This measure is called response time. The
formula to calculate Response Time = CPU Allocation Time(when the CPU was allocated for the
first) – Arrival Time
6.Completion time: This is the time when the process completes its execution.
6 | Page
5.0Actual Procedure Followed.
• Collected Information
• Analyzed the data collected to be used in the project
• wrote algorithm
• prepared flowchart
• implemented the algorithm into the code
• Interpreted the code and saw whether the output was right
• Presenting the project to the guide/subject teacher for confirmation
• Editing and revising the content
• Report presentation
• Final submission

1. First Come First Serve CPU scheduling algorithm:

In the "First come first serve" scheduling algorithm, as the name suggests, the process
which arrives first, gets executed first, or we can say that the process which requests the
CPU first, gets the CPU allocated first.
First Come First Serve, is just like FIFO (First in First out) Queue data structure, where
the data element which is added to the queue first, is the one who leaves the queue first.
This is used in Batch Systems. It's easy to understand and implement programmatically,
using a Queue data structure, where a new process enters through the tail of the queue,
and the scheduler selects process from the head of the queue. A perfect real-life example
of FCFS scheduling is buying tickets at ticket counter.

ALGORITHM:

Step 1: Input the number of processes required to be scheduled using FCFS, burst time for
each process and its arrival time.
Step 2: Using enhanced bubble sort technique, sort the all given processes in ascending order
according to arrival time in a ready queue.
Step 3: Calculate the Finish Time, Turn Around Time and Waiting Time for each process
which in turn help to calculate Average Waiting Time and Average Turn Around Time
required by CPU to schedule given set of process using FCFS.
Step 3.1: for i = 0, Finish Time T 0 = Arrival Time T 0 + Burst Time T 0
Step 3.2: for i >= 1, Finish Time T i = Burst Time T i + Finish Time T i - 1
Step 3.3: for i = 0, Turn Around Time T 0 = Finish Time T 0 - Arrival Time T 0
Step 3.4: for i >= 1, Turn Around Time T i = Finish Time T i - Arrival Time T i
Step 3.5: for i = 0, Waiting Time T 0 = Turn Around Time T 0 - Burst Time T 0
Step 3.6: for i >= 1, Waiting Time T i = Turn Around Time T i - Burst Time T i - 1
Step 4: Process with less arrival time comes first and gets scheduled first by the CPU.
Step 5: Calculate the Average Waiting Time and Average Turn Around Time.
Step 6: Stop.
7 | Page
FLOW CHART:

8 | Page
1. Shortest Job First CPU scheduling algorithm:

It is a Non Pre-emptive Algorithm.


The algorithm associates with each process length of the latter's next CPU burst.
When the CPU is unavailable, it is assigned to the process that has the smallest next CPU
burst. If two processes have the same length next CPU burst, FCFS scheduling is used to
break the tie.
The SJF scheduling algorithm is probably optimal. The real difficulty with the SJF is
algorithm knows the length of the next CPU request. Although SJF algorithm is optimal, it
cannot be implemented at the level of Short Term Scheduling(STS) since there is no way to
know the length of next CPU burst, but we may be able to approximate the length of next
CPU burst and predict its value and hence pick the process with shortest predicted CPU
burst.

ALGORITHM:

Step 1: Input the number of processes required to be scheduled using SJF, burst time for each
process and its arrival time.
Step 2: Store all the distinct arrival times in an array sorted in an ascending order.
Step 3: Filter out the processes that arrive at the same time and store them in another array.
Step 4: Find the process which has the smallest CPU burst and allocate the processor to that
process.
Step 5: In this manner, continue this process till all the processes run to completion.
Step 6: Calculate the Finish Time, Turn Around Time and Waiting Time for each process
which in turn help to calculate Average Waiting Time and Average Turn Around Time
required by CPU to schedule given set of process using FCFS.
Step 6.1: for i = 0, Finish Time T 0 = Arrival Time T 0 + Burst Time T 0
Step 6.2: for i >= 1, Finish Time T i = Burst Time T i + Finish Time T i - 1
Step 6.3: for i = 0, Turn Around Time T 0 = Finish Time T 0 - Arrival Time T 0
Step 6.4: for i >= 1, Turn Around Time T i = Finish Time T i - Arrival Time T i
Step 6.5: for i = 0, Waiting Time T 0 = Turn Around Time T 0 - Burst Time T 0
Step 6.6: for i >= 1, Waiting Time T i = Turn Around Time T i - Burst Time T i - 1
Step 7: Calculate the Average Waiting Time and Average Turn Around Time.
Step 8: Stop.

9 | Page
FLOW CHART:

10 | Page
1. Shortest Remaining Time CPU scheduling algorithm:

It is Pre-emptive SJF.
The choice arises when a new process arrives at the ready queue while a previous process is
executing. The new process may have a shorter next CPU burst that what is left of the
currently executing process. A pre-empt SJF algorithm will pre-empt the currently executing
process.

ALGORITHM:

Step 1: Input the number of processes required to be scheduled using SRT, burst time for
each process and its arrival time.
Step 2: Store all the distinct arrival times in an array sorted in an ascending order.
Step 3: Filter out the processes that arrive at the same time and store them in another array.
Step 4: Find the process which has the smallest CPU burst and allocate the processor to that
process. NOTE: This time the process having the smallest CPU burst at that very instance of
time will pre-empt the processor.
Step 5: In this manner, continue this process till all the processes run to completion.
Step 6: Calculate the Finish Time, Turn Around Time and Waiting Time for each process
which in turn help to calculate Average Waiting Time and Average Turn Around Time
required by CPU to schedule given set of process using FCFS.
Step 6.1: for i = 0, Finish Time T 0 = Arrival Time T 0 + Burst Time T 0
Step 6.2: for i >= 1, Finish Time T i = Burst Time T i + Finish Time T i - 1
Step 6.3: for i = 0, Turn Around Time T 0 = Finish Time T 0 - Arrival Time T 0
Step 6.4: for i >= 1, Turn Around Time T i = Finish Time T i - Arrival Time T i
Step 6.5: for i = 0, Waiting Time T 0 = Turn Around Time T 0 - Burst Time T 0
Step 6.6: for i >= 1, Waiting Time T i = Turn Around Time T i - Burst Time T i - 1
Step 7: Calculate the Average Waiting Time and Average Turn Around Time.
Step 8: Stop.

11 | Page
FLOW CHART:

12 | Page
CODE for GUI:

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./assets/css/custom.css">
<link rel="stylesheet" href="./assets/css/responsive.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!--Font awesome-->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css
">
</head>
<body class="bg-dark">
<div class="container d-flex flex-d-col f-align-items-center">
<section class="p-t-20 p-b-20 text-center m-b-40">
<form class="form-control">
<h3>Select the Algorithm:</h3>
<select id="algorithms">
<option value="firstComeFirstServe">First Come First
Serve</option>
<option value="shortestJobFirst">Shortest Job First</option>
<option value="shortestRemainingTime">Shortest Remaining
Time</option>
</select>
</form>
</section>
<table class="table border-FFF responsive-100 text-center">
<thead class="border-FFF">
<td class="td p-10 f-s-2">Process</td>
<td class="td p-10 f-s-2">CPU Burst</td>
<td class="td p-10 f-s-2">Arrival Time</td>
</thead>
<tbody id="tableBody">

</tbody>
</table>
<button class="btn rounded-btn m-t-10" id="addBtn1">Add a Process to the
above table!</button>
<!--This is the dialog box which is to be shown when the user hits add a
process!-->

13 | Page
<form class="d-none form-control border-FFF p-ab responsive-50 flex-d-col
f-align-items-center bg-dark t-translate" id="popUp">
<button class="btn rounded-btn f-self-align-end p-10"
id="closeBtn">X</button>
<h3>Fill The Process Details!</h3>
<label for="processName">Process Name: </label>
<input type="text" class="input-box m-b-5 d-block text-center"
id="processName">
<label for="cpuBurst">CPU Burst: </label>
<input type="number" class="input-box m-b-5 d-block text-center"
id="cpuBurst">
<label for="arrivalTime">Arrival time: </label>
<input type="number" class="input-box m-b-5 d-block text-center"
id="arrivalTime">
<button class="btn rounded-btn m-t-10 m-b-80" id="addBtn2">Add
Process</button>
</form>
<button class="btn rounded-btn m-t-10 m-b-40 " id="solveBtn">SOLVE!</button>
<div class="b-b responsive-100"></div>
<section id="answerTemplate" class="d-none">
<section class="m-b-20">
<h3 class="text-center">Answer</h3>
<p class="f-s-1">Step 1: Prepare the Gantt chart</p>
<table>
<thead id="ganttChart">
</thead>
<tbody>
<tr id="timeLine">
</tr>
</tbody>
</table>
</section>

<section class="m-b-20">
<p class="f-s-1">Step 2: Prepare a detailed table</p>
<table class="table border-FFF responsive-100 text-center">
<thead class="border-FFF">
<td class="td p-10 f-s-2">Process</td>
<td class="td p-10 f-s-2">CPU Burst</td>
<td class="td p-10 f-s-2">Arrival Time</td>
<td class="td p-10 f-s-2">Start Time</td>
<td class="td p-10 f-s-2">Finish Time</td>
</thead>
<tbody id="answerTableBody">

</tbody>

14 | Page
</table>
</section>

<section class="m-b-20">
<p class="f-s-1">Step 3: Calculate the turn-around-time</p>
<p class="f-s-1 p-10 border-FFF">TurnAroundTime = FinishTime -
ArrivalTime</p>
<div id="tatCalculation">

</div>
</section>

<section class="m-b-20">
<p class="f-s-1">Step 4: Calculate the Wait-time</p>
<p class="f-s-1 p-10 border-FFF">WaitTime = TurnAroundTime - CPU
burst</p>
<div id="wtCalculation">

</div>
</section>

<section class="m-b-20">
<p class="f-s-1">Step 5: Calculate the Response-time</p>
<p class="f-s-1 p-10 border-FFF">ResponseTime = StartTime -
ArrivalTime</p>
<div id="rtCalculation">

</div>
</section>
</section>
</div>
<script src="./assets/js/custom.js"></script>
</body>
</html>

15 | Page
Actual Implementations:
/******************************************************************************
**********************************PCB Section*********************************
*******************************************************************************/
class PCB {
static counter = 0;
constructor(processName, cpuBurst, aTime, createNewPcb) {
if(createNewPcb === 'true')
this.id = PCB.generatePCBId();
this.processState = 'new';
this.processName = processName;
this.cpuBurstLeft = this.cpuBurst = cpuBurst;
this.aTime = aTime;
this.startTime = null;
this.finishTime = null;
this.turnAroundTime = null;
this.waitTime = null;
this.responseTime = null;
}
createCopyOf = () =>{
let copy = new PCB(this.processName, this.cpuBurst, this.aTime, 'false');
copy.id = this.id;
return copy;
}
static generatePCBId = () => ++(PCB.counter);
setTAT = turnAroundTime => this.turnAroundTime = turnAroundTime;
setWT = waitTime => this.waitTime = waitTime;
setRT = responseTime => this.responseTime = responseTime;
}
/******************************************************************************
**********************************Variables Section*********************************
*******************************************************************************/
let currentAlgo, timeLineForPreEmptiveAlgos, chartForPreEmptiveAlgos;
let pcbs = new Array();
let readyQueue = new Array();
let backupQueue = new Array();//stores the previous data!
/******************************************************************************
**********************************DOM Section*********************************
*******************************************************************************/
const addBtn1Elem = document.getElementById('addBtn1');
const popUpElem = document.getElementById('popUp');
const addBtn2Elem = document.getElementById('addBtn2');
const algoSelectorElem = document.getElementById('algorithms');
const tableBodyElem = document.getElementById('tableBody');
const solveBtnElem = document.getElementById('solveBtn');

16 | Page
//Pop up dom
const processNameElem = document.getElementById('processName');
const cpuBurstElem = document.getElementById('cpuBurst');
const aTimeElem = document.getElementById('arrivalTime');

//Answer
const answerTemplateElem = document.getElementById('answerTemplate');
const ganttChartElem = document.getElementById('ganttChart');
const timeLineElem = document.getElementById('timeLine');
const answerTableBodyElem = document.getElementById('answerTableBody');
const tatCalculationElem = document.getElementById('tatCalculation');
const wtCalculationElem = document.getElementById('wtCalculation');
const rtCalculationElem = document.getElementById('rtCalculation');

function addEventListeners() {
algoSelectorElem.addEventListener('change', handlesAlgoChange);
addBtn1Elem.addEventListener('click', handlesAddBtn1);//Add process to the table
document.getElementById('closeBtn').addEventListener('click', closePopup);
addBtn2Elem.addEventListener('click', handlesAddBtn2);//Pop up 's add Button
solveBtnElem.addEventListener('click', compute);
}
/******************************************************************************
**********************************Main Section*********************************
*******************************************************************************/
(() => {
addEventListeners();
initializer();
})();

function initializer() {
currentAlgo='firstComeFirstServe';
}

function emptyTheTableOfProcesses() {
tableBodyElem.innerHTML = '';
}

function handlesAlgoChange(evt) {
currentAlgo = algoSelectorElem.value;
timeLineForPreEmptiveAlgos = chartForPreEmptiveAlgos = '';
}

function handlesAddBtn1(evt) {
showPopUp();
}

17 | Page
function handlesAddBtn2(evt) {
evt.preventDefault();
let pcb;
let cpuBurst = parseInt(cpuBurstElem.value);
let arrivalTime = parseInt(aTimeElem.value);

pcb = new PCB(processNameElem.value, cpuBurst, arrivalTime, 'true');


pcbs.push(pcb);
hide(popUpElem);
renderToTable();
}

function closePopup(evt) {
evt.preventDefault();
hide(popUpElem);
}

function renderToTable() {
let rows = '';
for(let i=0; i<pcbs.length; i++) {
rows += `
<tr>
<td class="p-10 td">${pcbs[i].processName}</td>
<td class="p-10 td">${pcbs[i].cpuBurst}</td>
<td class="p-10 td">${pcbs[i].aTime}</td>
</tr>
`;
}
setElement(tableBodyElem, rows);
}

function renderGanttChart() {
let chart, cpuBurst, timeLine, time;
chart = '';
time = readyQueue[0].aTime;
console.log('Time of chart: ', time);
timeLine = `<td class="text-left">${time}</td>`;
for(let i=0; i<readyQueue.length; i++) {
chart += `
<td class="td p-10 f-s-2 text-center">${readyQueue[i].processName}</td>
`;
cpuBurst = readyQueue[i].cpuBurst;
readyQueue[i].startTime = time;
time += cpuBurst;
readyQueue[i].finishTime = time;
timeLine += `

18 | Page
<td class="text-left">${time}</td>
`;
}
console.log("ReadyQueue: ", readyQueue);
show(answerTemplateElem);
setElement(ganttChartElem, chart);
setElement(timeLineElem, timeLine);
prepareADetailedTable();
}

function prepareADetailedTable() {
let rows = '';
for(let i=0; i<pcbs.length; i++) {
rows += `
<tr>
<td class="p-10 td">${pcbs[i].processName}</td>
<td class="p-10 td">${pcbs[i].cpuBurst}</td>
<td class="p-10 td">${pcbs[i].aTime}</td>
<td class="p-10 td">${pcbs[i].startTime}</td>
<td class="p-10 td">${pcbs[i].finishTime}</td>
</tr>
`;
}
setElement(answerTableBodyElem, rows);
computeTAT();
}

function displayTATwtRTComputations() {
let tatOutput, wtOutput, rtOutput;
let totalTAT, totalWT, totalRT;
totalRT=totalTAT=totalWT=0;
tatOutput = wtOutput = rtOutput = '';
for(let i=0; i<pcbs.length; i++) {
tatOutput += `
<p class="f-s-1">${pcbs[i].processName} = ${pcbs[i].finishTime} -
${pcbs[i].aTime} = ${pcbs[i].turnAroundTime}</p>
`;
totalTAT += pcbs[i].turnAroundTime;
wtOutput += `
<p class="f-s-1">${pcbs[i].processName} = ${pcbs[i].turnAroundTime} -
${pcbs[i].cpuBurst} = ${pcbs[i].waitTime}</p>
`;
totalWT += pcbs[i].waitTime;
rtOutput += `
<p class="f-s-1">${pcbs[i].processName} = ${pcbs[i].startTime} -
${pcbs[i].aTime} = ${pcbs[i].responseTime}</p>

19 | Page
`;
totalRT += pcbs[i].responseTime;
}
let avgTAT = (totalTAT/pcbs.length);
let avgWT = (totalWT/pcbs.length);
let avgRT = (totalRT/pcbs.length);
tatOutput += `
<p class="f-s-1">Total = ${totalTAT}</p>
<p class="f-s-1 border-FFF">Avg of TAT = ${totalTAT}/${pcbs.length} =
${avgTAT}</p>
`;
wtOutput += `
<p class="f-s-1">Total = ${totalWT}</p>
<p class="f-s-1 border-FFF">Avg of WT = ${totalWT}/${pcbs.length} =
${avgWT}</p>
`;
rtOutput += `
<p class="f-s-1">Total = ${totalRT}</p>
<p class="f-s-1 border-FFF">Avg of RT = ${totalRT}/${pcbs.length} =
${avgRT}</p>
`;
setElement(tatCalculationElem, tatOutput);
setElement(wtCalculationElem, wtOutput);
setElement(rtCalculationElem, rtOutput);
}

function computeTAT() {
//TAT = FT - AT
let turnAroundTime, waitTime, responseTime;
pcbs.forEach(pcb => {
turnAroundTime = pcb.finishTime - pcb.aTime;
pcb.setTAT(turnAroundTime);
waitTime = pcb.turnAroundTime - pcb.cpuBurst;
pcb.setWT(waitTime);
responseTime = pcb.startTime - pcb.aTime;
pcb.setRT(responseTime);
});
displayTATwtRTComputations();
}

function compute(evt) {
readyQueue = new Array();
if(currentAlgo === 'firstComeFirstServe') {
prepareGanttForFirstComeFirstServeAlgo(); }
else if(currentAlgo === 'shortestJobFirst') {
prepareGanttForShortestJobFirstAlgo(); }

20 | Page
else if(currentAlgo === 'shortestRemainingTime') {
prepareGanttForShortestRemainingTimeAlgo();}
}

function ascSortArrivalTime() {
let i, j, flag;
flag = 1;
pcbs.forEach(elem => {
readyQueue.push(elem);
});
for(i=0; i<(readyQueue.length-1) && flag === 1; i++) {
flag = 0;
for(j=0; j<(readyQueue.length-1-i); j++) {
if((readyQueue[j].aTime) > (readyQueue[j+1].aTime)) {
temp = readyQueue[j];
readyQueue[j] = readyQueue[j+1];
readyQueue[j+1] = temp;
flag = 1;
}
}
}
}

function prepareGanttForFirstComeFirstServeAlgo() {
ascSortArrivalTime();//sorted the pcbs ka array
renderGanttChart();
}

function getShortestJob(jobsWithSameArrivalTime) {
let shortestJob = jobsWithSameArrivalTime[0];

for(let j=1; j<jobsWithSameArrivalTime.length; j++) {


if(jobsWithSameArrivalTime[j].cpuBurst < shortestJob.cpuBurst) {
shortestJob = jobsWithSameArrivalTime[j];
}
}
return shortestJob;
}

function removeIdFrom(queue, IdOfJob) {


for(let i=0; i<queue.length; i++) {
if(queue[i].id === IdOfJob) {
for(let j=i; j<queue.length; j++)
queue[j] = queue[j+1];
(queue.length)--;
break;

21 | Page
}
}
}

function prepareGanttForShortestJobFirstAlgo() {
let distinctTime = new Array();//distinct arrival times
let queueOfJobs = new Array();//copy of pcbs are stored here!In order to
customize the time without disturbing the current state of the og Pcbs
//taking BackUP
pcbs.forEach((pcb) => {
queueOfJobs.push(pcb);
if(!distinctTime.includes(pcb.aTime)) {distinctTime.push(pcb.aTime);}
});
let ascTime = distinctTime.sort((num1, num2) => { return (num1-num2);});
let currentTime = ascTime[0];//starting most time

let i=0;
while(i<distinctTime.length || queueOfJobs.length !== 0) {
let jobsWithSameArrivalTime = queueOfJobs.filter(job => {
return (job.aTime === distinctTime[i] || job.aTime <= currentTime);
});
if(jobsWithSameArrivalTime.length > 1) {
let shortJob = getShortestJob(jobsWithSameArrivalTime);
readyQueue.push(shortJob);
currentTime += shortJob.cpuBurst;
removeIdFrom(queueOfJobs, shortJob.id);
} else {
readyQueue.push(jobsWithSameArrivalTime[0]);
currentTime += jobsWithSameArrivalTime[0].cpuBurst;
removeIdFrom(queueOfJobs, jobsWithSameArrivalTime[0].id);
}
if(queueOfJobs.length === 0)
break;
if((i+1) !== distinctTime.length)
i++;
}
renderGanttChart();
}

function ascSortCPUBurst(jobsPresentAtCurrentTime) {
let i, j, flag;
flag = 1;

for(i=0; i<(jobsPresentAtCurrentTime.length-1) && flag === 1; i++) {


flag = 0;
for(j=0; j<(jobsPresentAtCurrentTime.length-1-i); j++) {

22 | Page
if((jobsPresentAtCurrentTime[j].cpuBurstLeft) >
(jobsPresentAtCurrentTime[j+1].cpuBurstLeft)) {
temp = jobsPresentAtCurrentTime[j];
jobsPresentAtCurrentTime[j] = jobsPresentAtCurrentTime[j+1];
jobsPresentAtCurrentTime[j+1] = temp;
flag = 1;
}
}
}
}

function isPresentIn(queue, id) {


for(let i=0; i<queue.length; i++) {
if(queue[i].id === id){
return true;
}
}
return false;
}

function appendForPreEmptiveAlgos(process, time) {


chartForPreEmptiveAlgos += `
<td class="td p-10 f-s-2 text-center">${process.processName}</td>
`;
timeLineForPreEmptiveAlgos += `
<td class="text-left">${time}</td>
`;
}

function renderGanttChartForPreEmptiveAlgos() {
show(answerTemplateElem);
setElement(ganttChartElem ,chartForPreEmptiveAlgos);
setElement(timeLineElem, timeLineForPreEmptiveAlgos);
prepareADetailedTable();
}

function prepareGanttForShortestRemainingTimeAlgo() {
let uniqueArrivalTimes = new Array();//unique arrival times
let queueOfJobs = new Array();
pcbs.forEach((pcb) => {
queueOfJobs.push(pcb);
if(!uniqueArrivalTimes.includes(pcb.aTime))
{uniqueArrivalTimes.push(pcb.aTime);}
});
let sortedUniqueTime = uniqueArrivalTimes.sort((time1, time2) => { return
(time1-time2);});

23 | Page
let currentTime = sortedUniqueTime[0];
timeLineForPreEmptiveAlgos += `<td class="text-left">${currentTime}</td>`;
let i = 0;
let prevProcess = null;
while(queueOfJobs.length !== 0) {
let jobsPresentAtCurrentTime = queueOfJobs.filter(job => (job.aTime <=
sortedUniqueTime[i]));
ascSortCPUBurst(jobsPresentAtCurrentTime);
let shortestJob = jobsPresentAtCurrentTime[0];
///This section handles preEmption
if(prevProcess !== null) {
if(isPresentIn(jobsPresentAtCurrentTime, prevProcess.id) &&
jobsPresentAtCurrentTime[0].id !== prevProcess.id) {
appendForPreEmptiveAlgos(prevProcess, currentTime);
}
}
///
if(shortestJob.processState === 'new') {
shortestJob.processState = 'running';
shortestJob.startTime = currentTime;
}
//checking whether there exist arrival time of next process in the
sortedUniqueTime array
if(sortedUniqueTime.length > (i+1)) {
let arrivalTimeOfNextProcess = sortedUniqueTime[i+1];
while(currentTime < arrivalTimeOfNextProcess && shortestJob.cpuBurstLeft
> 0) {
shortestJob.cpuBurstLeft--;
currentTime++;
}
} else {
currentTime += shortestJob.cpuBurstLeft;
shortestJob.cpuBurstLeft = 0;
}
//Did the process run to completion?
if(shortestJob.cpuBurstLeft === 0) {
prevProcess = null;
shortestJob.finishTime = currentTime;
shortestJob.processState = 'exit';
removeIdFrom(queueOfJobs, shortestJob.id);
appendForPreEmptiveAlgos(shortestJob, shortestJob.finishTime);
} else {
shortestJob.processState = 'ready';
prevProcess = shortestJob;//for detecting pre-emption!
}

24 | Page
if((i+1) < sortedUniqueTime.length) {
i++;
}
}
renderGanttChartForPreEmptiveAlgos();
}

/******************************************************************************
**********************************Helper Section*******************************
*******************************************************************************/
function setElement(elem, content) {
elem.innerHTML = content;
}

function hide(elem) {
elem.style.display = 'none';
}

function show(elem) {
elem.style.display = 'block';
}

function showPopUp() {
popUpElem.style.display = 'flex';
}

6.0Actual Resources Used:


Sr.No. Equipment Name with Broad Specification Remark if any

1 Laptop Inspiron 3509, i5, 11th Gen, 8GB RAM, 1TB HDD

2 Windows

3 Visual Studio Code

7.0 Outputs of the Micro-Projects:

25 | Page
9. Skill Developed / learning out of this Micro-Project
1. We learned various scheduling algorithms.
2. Implemented the algorithm and observed the functionality
3. We understood the importance of working in team and listening to each other's ideas and
views to further improve our project and our knowledge.
4. We have also learnt to coordinate with the team members and support each other for
successful completion of the project.
5. We learnt to follow the deadlines and complete our work within specified time frame.

10. Applications of this Micro-Project


1. Operating system uses these scheduling algorithms for scheduling the processes.

26 | Page
Annexure – III

Suggested Rubric for Assessment of Micro-Project

S. Characteristic to Poor Average Good Excellent


No. be assessed ( Marks 1 - 3 ) ( Marks 4 - 5 ) ( Marks 6 - 8 ) ( Marks 9- 10 )

1 Relevance to the Relate to very Related to some Take care of Take care of more
course few LOs LOs at-least one than one CO
CO

2 Literature review Not more than At-least 5 At –least 7 About 10 relevant


/information two sources relevant relevant sources, most latest
collection very old sources, at least sources, most
reference 2 latest latest

3 Completion of the Completed less Completed 50 Completed 60 Completed more


Target as per than 50% to 60% to 80% than 80 %
project proposal

4 Analysis of Data Data neither Sufficient and Sufficient and Enough data
and representation organized nor appropriate appropriate collected and
presented enough data not enough data sufficient and
well presented well. but not used. presenting data.

5 Quality of Incomplete Just assembled Well Well assembled


Prototype/Model Programming and some codeis assembled and with proper
code not functioning functioning functioning parts..
well. parts.

6 Report Preparation Very short, Nearly Detailed, Very detailed,


Details about sufficient and correct and correct, clear
methods, correct details clear description of
details are there in Sufficient methods, and
wrong presentation. Graphic conclusions.
Description.

7 Presentation of Major Includes major Includes major Well organized,


the micro project information is information information includes major
not included, but not well and well information ,well
information is organized and organized but presented
not well not presented not presented
organized. well well

8 Defense Could not Replied to Replied Replied most of the


reply to considerable properly to questions properly
considerable number of considerable
number of questions but number of
question. not very question.
properly

27 | Page
Annexure – IV

Micro Project Evaluation Sheet


Name of Student: Hemant.Bhatia, Gaurav.Punjabi, Pooja.Makhija
Enrollment No: 2000040356-358
Name of Program: COMPUTER ENGINEERING CO5I-A
Semester: 5th
Course Title: OSY
Course Code:22516
Title of the Micro-Project:
Implementation of Shortest Job First, FCFS and Shortest Remaining Time CPU Scheduling
Algorithm.
Cos addressed by Micro Project: (Tick appropriate COs)

1. Install operating system and configure it. [✔]


2. Apply scheduling algorithms to calculate turnaround time and average waiting
time.[✔]

Sr. Characteristic to be Poor Average Good Excellent Sub Total


No. assessed ( Marks1- 3) (Marks 4-5) (Marks 6-8) ( Marks9-10)
(A) Process and Product Assessment (Convert Above Total marks out of 6 Marks)

1 Relevance to the course

2 Information Collection

Completion of the Target


3
as per project proposal

Analysis of Data and


4
representation

Quality of
5
Prototype/Model

6 Report Preparation

(B) Individual Presentation / Viva (Convert above total marks out of 4 marks)

7 Presentation

8 Defense

28 | Page
Group Micro Project Evaluation

Total
Roll Process and Product Individual Presentation / Marks
Name
No. Assessment (6 Marks) Viva (4 Marks)
10

1. Hemant.Bhatia

2. Gaurav.Punjabi

3. Pooja.Makhija

Comments/Suggestions about team work/leadership/inter-personal communication (if any)

The project was implemented with good leadership & teamwork with active co-operation of all the
team members. Everyone contributed equally and met with good outcome. Hence, overall project
was done with harmony with good team spirit.

Name and Designation of Teacher: Mrs.(Lecturer)

Dated Signature

29 | Page

You might also like