Home » Algorithms

Implementation of Shortest Job First (SJF) Non-Preemptive CPU scheduling algorithm using C++

In this article, we are going to learn about implementation of shortest job first (SJF) Non-preemptive scheduling algorithm using C++ program.
Submitted by Aleesha Ali, on January 26, 2018

Non-preemptive: We cannot remove a process until it completes it execution.

Scheduling criteria tells us that any algorithm is how much efficient, the main criteria of scheduling are given below:

  • CPU Utilization
  • Throughput
  • Arrival time
  • Turn around time
  • Waiting time
  • Completion time
  • Burst time

*Ready Queue is a queue where all the processes wait to get CPU for its execution.

CPU Utilization: The amount of time CPU is busy.

Throughput: The number of process computed per unit time.

Arrival time: The time at which the process enters into ready queue.

Turn around time: The interval between the time of submission of a process to the time of completion.

Waiting time: The total amount of the time a process spends in ready queue.

Completion time: The time at which process completes its execution.

Burst time: The time needed by CPU to completes its execution.

Shortest Job First Algorithm

In this scheduling algorithm the process having minimum burst time will execute first.

C++ Program for SJF scheduling

//Implementation fo SHORTEST JOB FIRST Using C++

#include <iostream>
#include <algorithm>
using namespace std;

int ab;

typedef struct schedule
	string pro_id;
	int at,bt,ct,ta,wt;

	artime = Arrival time,
	bt = Burst time,
	ct = Completion time,
	ta = Turn around time,
	wt = Waiting time


bool compare(schedule a,schedule b)
	return a.at < b.at;
	/* This process will always return TRUE 
	if above condition comes*/

bool compare2(schedule a,schedule b)
	return a.bt < b.bt && a.at <= ab;
	/* This process will always return TRUE 
	if above condition comes*/

int main()
	schedule pro[10];
	//An array of Processes
	int n,i,j;
	//n = number of processes, i= iteration variable

	cout<<"Enter the number of schedule::";
	cout<<"Enter the schedule id arrival time burst time :::";


	/*sort is a predefined funcion  defined in algorithm.h header file,
	it will sort the processes according to their arrival time*/


	// initial values





		//before executing make it in one statement
	return 0;


SJF algo implementation using C++ program

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.